Use local docker image with minikube Use local docker image with minikube docker docker

Use local docker image with minikube


The docker build does not know what you mean by your command, because flag -t requires specific format:

--tag , -t Name and optionally a tag in the ‘name:tag’ format

xxxxxxxxxx:~/Downloads$ docker build -t shivnilesh1109/spring-docker-01 .

So the proper command here should be:

docker build -t shivnilesh1109/spring-docker-01:v1(1) .(2)

(1) desired name of your container:tag(2) directory in which your dockerfile is.

After you proceed to minikube deployment, it will be enough just to run:kubectl run *desired name of deployment/pod* --image=*name of the container with tag* --image-pull-policy=Never

If this would not fix your issue, try adding the path to Dockerfile manually. I've tested this on my machine and error stopped after using proper tagging of the image and tested this also with full path to Dockerfile otherwise I had the same error as you.


For you UPDATE-2 question, also to help you to understand the port exposed in the Dockerfile and in the command kubectl expose.

Dockerfile:

The EXPOSE instruction does not actually publish the port. It functions as a type of documentation between the person who builds the image and the person who runs the container, about which ports are intended to be published.

For more details, see EXPOSE.

Kubectl expose:

--port: The port that the service should serve on. Copied from the resource being exposed, if unspecified

--target-port: Name or number for the port on the container that the service should direct traffic to. Optional.

For more details, see kubectl expose.

So I think you should add the parameters --target-port with the port that you exposed in the Dockerfile. And then the port mapping will be correct.


You can just create a Dockerfile with this content:

FROM shivnilesh1109/spring-docker-01

Then run:

docker build -t my-spring-docker-01 .