Use local docker image on minikube
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.
1 | > eval $(minikube docker- env ) |
This actually reuses the docker host from Minikube for your current bash session.
See for yourself.
1 2 3 4 5 6 | > 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.
1 2 3 4 | >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.
1 | docker commit 128ce006ecae dockerimage:version1 |
Then let’s run our custom image on minikube.
1 | kubectl create deployment test -image --image=dockerimage:version1 |
Let’s also expose the service
1 | kubectl expose deployment test -image -- type =LoadBalancer --port=80 |
Let’s take to the next level and try to wget our service
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | > 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 Commercial support is available at <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
1 | 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.
Published on Java Code Geeks with permission by Emmanouil Gkatziouras, partner at our JCG program. See the original article here: Use local docker image on minikube. Opinions expressed by Java Code Geeks contributors are their own. |