How to Use Own Docker Images on Minikube — Easy Way
This brief post will bring you a quick and an effective way to use your own build docker images / docker image dumps on minikube.
There are some articles like this explaining one method to use Own Local Docker Images With Minikube. For some cases: such as when you are building docker images from a library or a programming language tool like ballerina, you might not be able to use the above mentioned method. Example case: Try to compile this ballerina example with having followed previously mentioned method.
Easy way
Note: When you’re executing following commands, replace
myImage
with your docker image name. You might need to use sudo privileges to execute docker commands on your local machine.
Step 1:
First, you have to have the docker image dump file. If you have it already, move to step 2. Otherwise, on your local terminal, run following command.
docker save myImage > myImage.tar
Step 2:
Copy the image dump file into minikube cluster. Note that you’ll only need to replace image dump file name.
scp -i $(minikube ssh-key) myImage.tar docker@$(minikube ip):/home/docker/
Step 3:
ssh into minikube cluster. This will shift your local terminal to the minikube cluster’s terminal.
minikube ssh
Load docker image into minikube cluster’s own docker. Run following command on the minikube cluster’s terminal which was opened with previous command.
docker load -i myImage.tar
You may check whether the image is loaded correctly by running on the same terminal,
docker images
Exit the minikube custer’s terminal by,
exit
Step 4:
You’ll need to instruct the kubernetes to not to pull images from the repository by setting the image pull policy to never. You may do this by modifying containers
section in your deployment.yaml
file.
containers:
- image: myImage:v1.0
name: myContainer
imagePullPolicy: Never
Well, that’s it for the easy way of using your own docker images on the minikube. I hope this was a useful exercise to save your time and bandwidth, since the whole point of having minikube on the local machine is to develop and test everything locally. 😊