Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update a docker image in registry

I pushed my docker image to my private registry once, but when I want to push again that image I got these messages :

06-Sep-2016 10:54:10    Error response from daemon: Conflict: Tag latest is already set to image 2bcc77ac3ef5f5ce0442d9cae3652c0464b8f266db9ccd65b1638aadf60ebc39, if you want to replace it, please use -f option
The push refers to a repository [localhost.com:5000/proj/proj1] (len: 1)
06-Sep-2016 10:54:10    2bcc77ac3ef5: Image already exists
06-Sep-2016 10:54:10    2bcc77ac3ef5: Image already exists
06-Sep-2016 10:54:10    4f3b96c826b8: Image already exists
06-Sep-2016 10:54:11    84c030e02a98: Image already exists
06-Sep-2016 10:54:11    c7282372eb99: Image already exists
06-Sep-2016 10:54:11    1b449d63ca4e: Image already exists

I run these commands for updating my image in registry every time :

docker tag proj1 localhost.com:5000/proj/proj1 
docker push localhost.com:5000/proj/proj1
like image 380
Mehrdad Abdolghafari Avatar asked Sep 06 '16 15:09

Mehrdad Abdolghafari


2 Answers

The problem is with your docker tag command, getting this response:

Error response from daemon: Conflict: Tag latest is already set to image 2bcc77ac3ef5f5ce0442d9cae3652c0464b8f266db9ccd65b1638aadf60ebc39, if you want to replace it, please use -f option

It's because there is already an image on your local machine with that tag. If you want to remove the tag from that older image, you should use a docker rmi command. Remember to make sure that the older image still has one or more tags (e.g. with a build number), otherwise it will actually be removed.

To work through an example, assume that your local machine has the following images:

REPOSITORY                       TAG                 IMAGE ID
localhost.com:5000/proj/proj1    0.1                 2bcc77ac3ef5
localhost.com:5000/proj/proj1    latest              2bcc77ac3ef5
<none>                           <none>              d52cb651fb7a

Note that the first two rows are two different tags for the same image; the third row is your new image which you want to tag.

The first thing you want to do is to remove the latest tag from the existing image, leaving it with only the 0.1 tag:

docker rmi localhost.com:5000/proj/proj1:latest

That will leave you with the following image list:

REPOSITORY                       TAG                 IMAGE ID
localhost.com:5000/proj/proj1    0.1                 2bcc77ac3ef5
<none>                           <none>              d52cb651fb7a

You can now apply the version tag and the latest tag to the new image:

docker tag d52cb651fb7a localhost.com:5000/proj/proj1:0.2
docker tag d52cb651fb7a localhost.com:5000/proj/proj1:latest

That will give you the following image list:

REPOSITORY                       TAG                 IMAGE ID
localhost.com:5000/proj/proj1    0.1                 2bcc77ac3ef5
localhost.com:5000/proj/proj1    0.2                 d52cb651fb7a
localhost.com:5000/proj/proj1    latest              d52cb651fb7a

Now you can do the push:

docker push localhost.com:5000/proj/proj1:latest
like image 65
Vince Bowdren Avatar answered Sep 30 '22 16:09

Vince Bowdren


Short: Upgrade to the latest docker version (preferred) or use the -t tag option.

Your commands are the same as if you would issue the following two commands:

docker tag proj1:latest localhost.com:5000/proj/proj1:latest 
docker push localhost.com:5000/proj/proj1:latest

Older versions of Docker are complaining, since you try to overwrite an existing image with existing tag :latest.

The quick&dirty solution is to try with

docker tag -f proj1 localhost.com:5000/proj/proj1 
docker push -f localhost.com:5000/proj/proj1

This will allow to overwrite the existing image localhost.com:5000/proj/proj1:latest on older versions of Docker.

However, I recommend to upgrade docker to version >=1.12.0. There, the -t option is not available and not necessary anymore, since the image will always be replaced. This is the reason, why -f option is not described on the official documentation, but it is mentioned on the Docker Deprecated Engine Features page instead.

like image 41
Olli Avatar answered Sep 30 '22 16:09

Olli