1

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

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'

In yaml file i have given as

image: myImage 
imagePullPolicy: IfNotPresent

In local i am using docker-desktop and minikube.

I have tried multiple ways but only thing is working on to make tar of myImage and load in minikube. I have tried using eval $(minikube docker-env) but after this my image is not able to build because it's pulling base image from organization nexus server. Can anyone suggest anyother way?

Fritz Duchardt
  • 11,026
  • 4
  • 41
  • 60
ajay
  • 21
  • 7

3 Answers3

1

Unfortunately I can't comment yet so I have to post an answer. The image you're trying to pull, myImage does not exist in the local image cache of your kubernetes cluster. Running a docker image ls command should yield a list of images that are available locally. If docker doesn't find an image locally, it will (by default) then go to Docker Hub to find the image. Seeing as the image listed has no prefix like someOrganization\ the image is assumed to be an officially published image from DockerHub themselves. Since your locally built image isn't an official Dockerhub image it doesn't know what to run. So the core of the problem is that your minikube doesn't have access to wherever you built your image. Unfortunately I haven't used minikube before so i'm unable to comment on any intricacies of how to work with it. I would be remiss if I left my answer like that, though, so looking at the docs for minikube ( REF: https://minikube.sigs.k8s.io/docs/handbook/pushing/#1-pushing-directly-to-the-in-cluster-docker-daemon-docker-env ) you're doing the right thing with the eval.

Sooo... your minikube isn't stock/vanilla and it pulls from a company repo? Sounds like you need to alter your minikube or you should re-evaluate the base image you're using and fix the Dockerfile.

Sean
  • 33
  • 1
  • 6
1

To fix this, set imagePullPolicy to Never.

Ensure to set eval $(minikube docker-env) before building the image.

Fritz Duchardt
  • 11,026
  • 4
  • 41
  • 60
  • As i already said after setting eval $(minikube docker-env) before build. My build is failing with below error Sending build context to Docker daemon 129.4MB Step 1/28 : FROM nexus-repo:8097/ubi8/openjdk8:1.8.0_272 Get https://nexus-repo:8097/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers) – ajay Dec 23 '20 at 08:15
  • Yes, set "imagePullPolicy" to "Never" and this starts working. The point here is, that minikube does not need to pull the image if it is already in the local registry. With setting "eval $(minikube docker-env)" before building, you ensure that docker build places the image in minikubes local registry. – Fritz Duchardt Dec 23 '20 at 08:23
  • how can i provide imagePullPolicy never when building image using dockerfile ?? – ajay Dec 23 '20 at 08:34
  • You have to set this in your K8s manifest. It is outside of the scope of the Dockerfile. – Fritz Duchardt Dec 23 '20 at 08:37
  • Seems you are not getting my point. My build is failing when i am trying to build my image after setting eval $(minikube docker-env). When i build using without setting eval $(minikube docker-env) and yaml of k8s have imagepullpolicy is IfNotPresent then it's giving the error that i have put in my original question. this issue has been resolved once i have build as below without setting eval $(minikube docker-env) docker build -o - . > myImage.tar then load tar file in minikube terminal as docker load -i myImage.tar after this all is working. So my is any-other way except this – ajay Dec 23 '20 at 08:42
  • So, this base image is also a local image? If yes, ensure to also put this one into the local registry of your minikube, e.g. by building it after eval $(minikube docker-env) was set. – Fritz Duchardt Dec 23 '20 at 08:49
  • this is ubi from RHEL and we put in our nexus. Using this ubi i am trying to build image . – ajay Dec 23 '20 at 08:53
  • Then, the problem lies with minikube not being authenticated with your Nexus. You can fix this by ssh-ing onto minikube with "minikube ssh" and doing a "docker login" on your nexus. – Fritz Duchardt Dec 23 '20 at 09:11
  • minikube ssh ]0;docker@minikube: ~docker@minikube:~$ docker login -u admin -p admin123 :8097 WARNING! Using --password via the CLI is insecure. Use --password-stdin. Error response from daemon: Get https://:8097/v2/: http: server gave HTTP response to HTTPS client Getting above error – ajay Dec 23 '20 at 09:16
  • What is the error response code? The very same docker login works for you locally? – Fritz Duchardt Dec 23 '20 at 09:41
  • error response code how i can get ? same docker login is worked locally when i am not executing eval $(minikube docker-env) – ajay Dec 23 '20 at 11:47
0

Maybe this is a little bit late but... if anyone has the same issue, here is how I solved something like this:

  • You need to pass "Never" as imagePullPolicy:

    imagePullPolicy: Never

  • You need to load the image inside minikube:

    minikube image load myImage

After all this, just continue as usual:

kubectl apply -f whereverTheFileIs.yaml

Inushin
  • 19
  • 2