Reputation: 5280
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?
Upvotes: 13
Views: 9707
Reputation: 306
A really simple solution would be
minikube image load --daemon myImageName -p myProfileName
User the -p
flag if you are using a profile otherwise it can be skipped
minikube image ls -p myProfileName
Upvotes: 1
Reputation: 422
The image you created in the docker won't be available in the Minikube because Minikube have it's own docker daemon and it checks for the docker images there and DockerHub.
Follow the below steps to access the Minikube Docker daemon, build and deploy the docker image:
docker-env command
that outputs environment variables needed to point the local Docker daemon to the minikube internal Docker registry.minikube docker-env export DOCKER_TLS_VERIFY=”1" export DOCKER_HOST=”tcp://172.17.0.2:2376" export DOCKER_CERT_PATH=”/home/user/.minikube/certs” export MINIKUBE_ACTIVE_DOCKERD=”minikube”
#To point your shell to minikube’s docker-daemon, # run: eval $(minikube -p minikube docker-env)
To apply these variables,
eval $(minikube -p minikube docker-env)
Now need to build the image once again, so that it’s installed in the minikube registry, instead of the local one:
docker build . -t forketyfork/hello-world
forketyfork/hello-world is the name of the docker image.
Deploy the image to kubernetes or Minkube via the yaml configuartion file.
kubectl create -f helloworld.yml
helloworld.yml is the name of the yml/yaml file.
kubectl get pods
to get the status of the podsFor further reference, https://medium.com/swlh/how-to-run-locally-built-docker-images-in-kubernetes-b28fbc32cc1d
Upvotes: 2
Reputation: 3779
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
Upvotes: 32