Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes fails to run a docker image build locally

I am trying to run a docker image that I have build locally with Kubernetes.

Here is my command line:

kubectl run myImage --image=myImage --port 3030 --image-pull-policy=IfNotPresent

I have seen many peoples saying that we need to add the --image-pull-policy=IfNotPresent flag so Kubernetes can look for the image locally instead of Docker Hub, but I still get this error (from the Minikube dashboard on the pod, the service and the deployment).

Failed to pull image "myImage": rpc error: code = Unknown desc = Error response from daemon: pull access denied for myImage, repository does not exist or may require 'docker login'

But it looks like there is another issue here, I also tried --image-pull-policy=Never and it doesn't work either.

Any idea?

like image 344
Ludo Avatar asked Apr 18 '18 11:04

Ludo


People also ask

How do I run Docker images locally?

You can also run a Docker image from your own Docker file using the docker-compose command. With compose, you can configure your application's services and then you can start all services with a single command. For example, set up a docker-compose. yml like this in your repository root (where the Dockerfile is):

Can Kubernetes run Docker images?

Docker is still a useful tool for building containers, and the images that result from running docker build can still run in your Kubernetes cluster.


1 Answers

The image is not available in minikube.

Minikube uses separate docker daemon. That's why, even though the image exists in your machine, it is still missing inside minikube.

First, send the image to minikube by,

docker save myImage | (eval $(minikube docker-env) && docker load)

This command will save the image as tar archive, then loads the image in minikube by itself.

Next, use the image in your deployment with image-pull-policy set to IfNotPresent

kubectl run myImage --image=myImage --port 3030 --image-pull-policy=IfNotPresent
like image 71
Abdullah Al Maruf - Tuhin Avatar answered Oct 26 '22 21:10

Abdullah Al Maruf - Tuhin