How to use local docker images with Minikube? How to use local docker images with Minikube? kubernetes kubernetes

How to use local docker images with Minikube?


As the README describes, you can reuse the Docker daemon from Minikube with eval $(minikube docker-env).

So to use an image without uploading it, you can follow these steps:

  1. Set the environment variables with eval $(minikube docker-env)
  2. Build the image with the Docker daemon of Minikube (eg docker build -t my-image .)
  3. Set the image in the pod spec like the build tag (eg my-image)
  4. Set the imagePullPolicy to Never, otherwise Kubernetes will try to download the image.

Important note: You have to run eval $(minikube docker-env) on each terminal you want to use, since it only sets the environment variables for the current shell session.


What worked for me, based on the solution by @svenwltr:

# Start minikubeminikube start# Set docker enveval $(minikube docker-env)             # unix shellsminikube docker-env | Invoke-Expression # PowerShell# Build imagedocker build -t foo:0.0.1 .# Run in minikubekubectl run hello-foo --image=foo:0.0.1 --image-pull-policy=Never# Check that it's runningkubectl get pods


Notes:

  • This Answer isnt limited to minikube!

  • If wanting to create the registry on minikube's Docker then run eval $(minikube docker-env) first (to make docker available on the host machine's terminal).
    Otherwise enter in the virtual machine via minikube ssh, and then proceed with the following steps

  • depending on your operative system, minikube will automatically mount your homepath onto the VM.

  • as Eli stated, you'll need to add the local registry as insecure in order to use http (may not apply when using localhost but does apply if using the local hostname)
    Don't use http in production, make the effort for securing things up.


Use a local registry:

docker run -d -p 5000:5000 --restart=always --name local-registry registry:2

Now tag your image properly:

docker tag ubuntu localhost:5000/ubuntu

Note that localhost should be changed to dns name of the machine running registry container.

Now push your image to local registry:

docker push localhost:5000/ubuntu

You should be able to pull it back:

docker pull localhost:5000/ubuntu

Now change your yaml file to use the local registry.

Think about mounting volumes at appropriate location, to persist the images on the registry.