Update a docker image in registry
Asked Answered
A

3

16

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
Aerodyne answered 6/9, 2016 at 15:0 Comment(2)
If you just do the docker tag command without the docker push, do you still get the error?Bismuth
@VinceBowdren yes, but I want to update my registry with the same tagAerodyne
H
19

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.

Hypoblast answered 6/9, 2016 at 16:0 Comment(1)
The behavior of older version is just what I wanted. Is there a way to enable the forbid or warn of the replacement of an existing tag? Or is there an option to set whitelist to be allowed to replaced such as 'latest', and let others disallowed such as V1.0.1 ?Doorpost
B
7

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
Bismuth answered 6/9, 2016 at 16:2 Comment(0)
B
-1

Incase you are working on maven project, then like me you might have missed to build the jar again after making changes.

for me, what worked was

mvn clean package

Then docker build

docker build --no-cache -t image_name

then docker tag and docker push.

Baun answered 11/11, 2021 at 16:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.