72

I am trying to push an image to a local registry running in minikube but get the below error:

Successfully built ee84225eb459
Successfully tagged user/apiserver:0.0.1

$ docker push localhost:5000/user/apiserver:0.0.1

The push refers to a repository [localhost:5000/user/apiserver]
An image does not exist locally with the tag: localhost:5000/user/apiserver

I have already tried starting minikube with below:

minikube start --vm-driver xhyve --insecure-registry localhost:5000
eval $(minikube docker-env)
Neil
  • 24,551
  • 15
  • 60
  • 81
Amit Shah
  • 751
  • 1
  • 5
  • 7
  • For me, the answer was simple but annoying to find I forgot to tag my image with the **username** also i made it private do not know if thats really neccesary please let me know if thats the case. so other people can learn from it and me :) thnx for this post it was helpful. btw sorry I am a little bit off-topic. – Chastic Fy Jun 15 '19 at 16:06
  • 1
    `docker push` should really return a a clearer error message, like `push of image with tag X failed because no image with tag X was found`. – asmaier Feb 17 '22 at 17:07

9 Answers9

42

You need to tag and push the image. When tagging an image, you can use the image identifier (imageId). It is listed when showing the list of all images with docker images. Syntax and an example (using imageId) for creating a tag are:

docker tag <imageId or imageName> <hostname>:<repository-port>/<image>:<tag>
docker tag af340544ed62 example.com:18444/hello-world:mytag

Once the tag, which can be equivalent to a version, is created successfully, you can confirm its creation with docker images and issue the push with the syntax:

docker push <hostname>:<repository-port>/<image>:<tag>

There is an example for local nexus repository

fgul
  • 5,763
  • 2
  • 46
  • 32
  • 3
    Thank you for actually explaining how to add a tag. The top post does not detail this. Recommend this being the top post. – Dave Jun 16 '21 at 13:23
  • 1
    This is the best awnser about how to push image, because without tag you can't and thats the only post that explain how to add tag. Thanks! – Pablo Mariante Nov 23 '21 at 12:39
37

I was getting the same error, which OP is referring to, googling the exact phrase brought me here, but, in my case, I was pushing it to the default/public repository (hub.docker.com) instead of the local one. But as it turns out the issue was the same

This was my local image which I created on my disk

[root@ip-172-31-22-195 centos]# docker images
REPOSITORY             TAG       IMAGE ID       CREATED        SIZE
centos                 latest    927311af2297   20 hours ago   193MB

I tagged it like this:

 docker tag centos devopskalsym:latest

then confirmed the tag being created:

[root@ip-172-31-22-195 centos]# docker images
REPOSITORY             TAG       IMAGE ID       CREATED        SIZE
devopskalsym           latest    927311af2297   20 hours ago   193MB
centos                 latest    927311af2297   20 hours ago   193MB

Since my repository on docker hub was: devopskalsym/centos7, I tried to push it:

docker push devopskalsym/centos7:latest

and got the error:

[root@ip-172-31-22-195 centos]# docker push devopskalsym/centos7:latest
The push refers to repository [docker.io/devopskalsym/centos7]
An image does not exist locally with the tag: devopskalsym/centos7

so I removed the tag with:

[root@ip-172-31-22-195 centos]# docker rmi devopskalsym
Untagged: devopskalsym:latest

then re-tagged correctly with the format mentioned by @BMitch.

docker tag centos:latest devopskalsym/centos7:latest

the format used is this: docker tag local-image:tagname new-repo:tagname

now it correctly shows the images:

[root@ip-172-31-22-195 centos]# docker images
REPOSITORY             TAG       IMAGE ID       CREATED        SIZE
devopskalsym/centos7   latest    927311af2297   20 hours ago   193MB
centos                 latest    927311af2297   20 hours ago   193MB

then pushed it again:

docker push devopskalsym/centos7:latest

and it worked

[root@ip-172-31-22-195 centos]# docker push devopskalsym/centos7:latest
The push refers to repository [docker.io/devopskalsym/centos7]
b7d51bf3d09e: Pushing [==================================>                ]    132MB/193.3MB

Note: you might need to login with docker login

shabby
  • 3,002
  • 3
  • 39
  • 59
23
Successfully tagged user/apiserver:0.0.1

docker push localhost:5000/user/apiserver:0.0.1

Image tags need to include the registry name/port for you to push them anywhere other than the default registry (docker hub). So you need to tag your image as localhost:5000/user/apiserver:0.0.1 rather than user/apiserver:0.0.1. Then you'll be able to push to your local registry.

BMitch
  • 231,797
  • 42
  • 475
  • 450
  • Successfully built 8c921763a005 Successfully tagged localhost:5000/user/apiserver:0.0.1 docker push localhost:5000/user/apiserver:0.0.1 The push refers to a repository [localhost:5000/user/apiserver] Get http://localhost:5000/v2/: dial tcp 127.0.0.1:5000: getsockopt: connection refused – Amit Shah Dec 31 '17 at 05:35
  • Also this is after kubectl port-forward $POD 5000:5000 & where POD is my registry-7f8lq or registry pod which did not help either – Amit Shah Dec 31 '17 at 05:41
  • 1
    bash-3.2$ curl -X GET http://localhost:5000/v2/_catalog Handling connection for 5000 {"repositories":[]} – Amit Shah Dec 31 '17 at 05:43
  • You'll want to open a separate question for that. This is moving from why can't it find my image to why isn't my port forward working. – BMitch Dec 31 '17 at 10:50
  • Thanks - was able to get it to work with another local registry deployment and port forwarding - Reference link https://mtpereira.com/local-development-k8s.html – Amit Shah Dec 31 '17 at 23:21
12

I had an image

trip-bot                     latest     0c9e8f0367bc   36 minutes ago   955MB

And I was getting error

The push refers to repository [docker.io/ilkhr/trip-bot] An image does not exist locally with the tag: ilkhr/trip-bot

Solved the problem like this

$ docker tag 0c9e8f0367bc ilkhr/trip-bot:trip-bot

After that I did so

$ docker push ilkhr/trip-bot:trip-bot
  • The problem is regarding the host of the registry missing, the question asker already tagged with the username. Represented by `user`. This answer sadly does not add anything of value. Sorry. – Dennis van de Hoef - Xiotin Jun 20 '21 at 10:36
9
  1. first start with docker login with these commands:-

    docker login
    
  2. then check you image id / tag by this command

    docker images
    
  3. once you get your image id/tag then use this command to push to your dockerhub repository

    docker tag <imageId or tag> <dockerhub id>/<imagename>:<tag>
    

or for general you can use

    docker tag <imageId or tag> <hostname>:<repository-port>/<imagename>:<tag>

note replace angle brackets with your specific information

eon grey
  • 101
  • 2
  • 2
0

If you are trying to push to docker hub and get this tag error, have in mind that at the moment you build your image, you should state the username of your docker hub account in order to push it right.

So in my case, the correct command was

docker image build -t marcofloriano/hello-docker .

And not

docker image build -t hello-docker .

Marco Floriano
  • 318
  • 2
  • 6
  • 14
0

Like others said, issues are typically due to incorrect tagging.

Here is a working example deploying a docker to DockerHub.

The tag format is <namespace>/<repo_name>:<version>. The namespace is typically stored in the repository secrets. Note that it is convenient to assign a tag when building.

name: Docker Image CI

on:
  push:
    branches: [ "main" ]
    paths: ["Dockerfile",".github/workflows/docker-image.yaml"]

jobs:
  build:
    runs-on: ubuntu-latest
    # Docker Hub tag
    env:
      IMAGE_NAME: jupyter-book-gh
      IMAGE_VERSION: latest
    steps:
    - uses: actions/checkout@v3
    - name: Log in to DockerHub
      env:
        DOCKER_USER: ${{secrets.DOCKER_USER}}
        DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}}
      run: |
        docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
        echo "${{secrets.DOCKER_USER}}/$IMAGE_NAME:$IMAGE_VERSION"
    - name: Build the Docker image
      run: docker build . --file Dockerfile --tag ${{secrets.DOCKER_USER}}/$IMAGE_NAME:$IMAGE_VERSION
    - name: Push the Docker image
      run: docker push ${{secrets.DOCKER_USER}}/$IMAGE_NAME:$IMAGE_VERSION
Maciej Skorski
  • 2,303
  • 6
  • 14
0

I got this error when pushing to AWS ECR,

for me i had a typo, the format current now as of 2023 is

docker tag image-id <account-id>.dkr.ecr.<region-code>.amazonaws.com/<repo-name>:<tag>

I accidentally deleted the dkr word, and I was getting the same error.

Ref: https://docs.aws.amazon.com/AmazonECR/latest/userguide/docker-push-ecr-image.html

Shamsul Arefin
  • 1,771
  • 1
  • 21
  • 21
0

In addition to this answer, if you receive this error while pushing to AWS ECR inside of a script, ensure the file line endings are appropriate for your OS (LF for Linux/OSX vs CRLF for Windows). This can be changed in most IDEs. For example, in VSCode by clicking the following tray tool:

enter image description here

rcgardne
  • 46
  • 1
  • 6