You use Minikube and you want to run your development images that you create locally. This might seem tricky since Minikube needs to download your images from a registry however you images are being uploaded on your local registry.
In any case you can still use you local images with Minikube so let’s get started.
Before running any container let’s issue.
> eval $(minikube docker-env)
This actually reuses the docker host from Minikube for your current bash session.
See for yourself.
> minikube docker-env export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://192.168.99.101:2376" export DOCKER_CERT_PATH="/Users/gkatzioura/.minikube/certs" # Run this command to configure your shell: # eval $(minikube docker-env)
Then spin up an nginx image. Most of the commands are taken from this tutorial.
>docker run -d -p 8080:80 --name my-nginx nginx >docker ps --filter name=my-nginx CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 128ce006ecae nginx "nginx -g 'daemon of…" 13 seconds ago Up 12 seconds 0.0.0.0:8080->80/tcp my-nginx
Now let’s create an image from the running container.
docker commit 128ce006ecae dockerimage:version1
Then let’s run our custom image on minikube.
kubectl create deployment test-image --image=dockerimage:version1
Let’s also expose the service
kubectl expose deployment test-image --type=LoadBalancer --port=80
Let’s take to the next level and try to wget our service
> kubectl exec -it podwithbinbash /bin/bash bash-4.4# wget test-image Connecting to test-image (10.101.70.7:80) index.html 100% |***********************************************************************************************************| 612 0:00:00 ETA bash-4.4# cat index.html <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
Take extra attention that the above will work only on the terminal that you executed the command
eval $(minikube docker-env)
If you want to you can just setup your bash_profile to do it for every terminal but this is up to you.
Eventually this is one of the quick ways to use you local images on Minikube and most probably there are others available.
One thought on “Use local docker image on minikube.”