Hello, surely a newbie question but: is it possibl...
# getting-started
f
Hello, surely a newbie question but: is it possible to use local docker images when using Pulumi on a local dev machine? I have minikube set. Pulumi ready, working with Python. I tried
Copy code
artifacts = docker.Image(
    "artifacts-image",
    build=docker.DockerBuildArgs(
        context="./artifacts",
        dockerfile="artifacts/Dockerfile",
    ),
    image_name="artifacts",
    skip_push=True
)

artifacts_container = ContainerArgs(
    name="artifacts-container",
    image=artifacts.image_name,
)

deployment = Deployment(
    "backend",
    metadata=backend_metadata,
    spec=DeploymentSpecArgs(
        replicas=1,
        selector=app_selector,
        template=PodTemplateSpecArgs(
            metadata=backend_php_metadata,
            spec=PodSpecArgs(
                volumes=[
                ],
                init_containers=[
                    artifacts_container,
                ],
                containers=[
                ],
            ),
        ),
    ),
)
pulumi up
gives me the message
warning: [Pod backend-95bd4bd6-5c4c5f594c-bqb8t]: containers with incomplete status: [artifacts-container]
kubectl describe pod backend-95bd4bd6-5c4c5f594c-bqb8t
shows the error
Failed to pull image "artifacts": rpc error: code = Unknown desc = Error response from daemon: pull access denied for artifacts, repository does not exist or may require 'docker login': denied: requested access to the resource is denied
but the image is shown by
docker image ls
so it looks like it tries to get from some provider instead of locally. Is there a config somewhere to get images locally? https://github.com/pulumi/pulumi-docker/issues/148 was not really helpful or I must have missed something.
s
From your description, this sounds like a Kubernetes-Docker issue, not a Pulumi issue. You’re trying to use a container stored in the local Docker storage with Kubernetes, and Kubernetes is trying to pull it from a registry (which the local Docker storage is not). You’ll need to run a local registry and have your Pulumi code push the built container image to the registry, then have Kubernetes pull from that registry.
f
It feels a little crazy to have to do this when "just trying this solution". So tried (not really thinking it'd work) to use
eval $(minikube docker-env)
in the terminal I do
pulumi up
. To no avail as it would have been too easy. Next, let's register the image created with minikube.
Copy code
artifacts = docker.Image(
    "artifacts-image",
    build=docker.DockerBuildArgs(
        context="./artifacts",
        dockerfile="artifacts/Dockerfile",
    ),
    image_name="artifacts",
    skip_push=True
)

os.system("minikube image load artifacts")
Little
minikube image ls
and yup
<http://docker.io/library/artifacts:latest|docker.io/library/artifacts:latest>
looks to be present. But the container can't pull it it seems. Let's update its policy with
Copy code
artifacts_container = ContainerArgs(
    name="artifacts-container",
    image=artifacts.image_name,
    image_pull_policy="Never",
)
Still not enough. So yeah time to setup a local image repository.
Although I don't see the utility of the skip_push option if there is no way to not have to pull the image after creating it.
s
You might use the
skip_push
if you are just working locally with Docker (like building the image and then running a container from that image). The wrinkle here is Kubernetes. Sorry for the extra work of having to stand up a repository (there’s a quick-and-dirty registry you can run as a container, FWIW), but this is outside our control.
f
Woot, tried again a little more fresh and using the basic docker registry in localhost and it worked! Thanks for the explanations and pointers.