How to Use Local Docker Images With Minikube?
Pre-requisite: Shell Script
Minikube is a lightweight Kubernetes implementation that has only one master node. It is basically a VM that runs over a docker container and creates a Kubernetes environment. Now since minikube is itself like an isolated container the local docker images on your computer are not accessible in minikube docker. So if the image is available on the docker hub then it is pulled in minikube docker from the docker hub otherwise you may get an Image FallBack Error. So how to solve this issue? The answer is by loading Local Docker images into Minikube. There are mainly two methods to load local docker images into our minikube node.
Method 1: Docker env Command
eval $(minikube docker-env)
This command points our terminal to use the docker daemon inside minikube. So now all the docker commands we will run will be run on docker in the minikube cluster and not on our host machine. So now we can directly build the docker image in our minikube docker.
docker build -t my_image .
Example: Suppose we have a basic nodejs app that we want to build in our minikube cluster. The folder structure and docker file of the app are as follows:

Now we can just run the above two commands in our terminal.

As we can see the image has been successfully loaded in minikube.
Method 2: Using the Image Load Command
$ minikube image load my_image
This command can be used when we are having the image built in the docker of our host machine but want to load it into the minikube cluster. First, check if my_image exists in the host machine docker images:

Since the image my-image already exists in our host machine docker we can load it directly into our minikube cluster by image load command.

Now check in minikube docker for the image

Hence we have loaded the image successfully into Minikube.
Please Login to comment...