Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker 'latest' Tagging and Pushing

I have a docker image generated from my build process. I am looking to tag the latest build image with tag build id and 'latest'. I see two ways to do this.

First approach - (Add Multiple tags and Push once)

docker tag <id> <user>/<image>:build_id  
docker tag <id> <user>/<image>:latest  
docker push <user>/<image>

Second - Tag individually and push

docker tag <id> <user>/<image>:build_id  
docker push <user>/<image>:build_id

docker tag <id> <user>/<image>:latest  
docker push <user>/<image>:latest

The docker documentation says if there is an image in the registry with a specific tag already, then docker push with a new image with same tag would overwrite the earlier image.

  1. Are both First and Second Option specified above functionally the same?
  2. Is there any preferred way/Best practice?
like image 865
Sandesh Avatar asked Feb 03 '18 07:02

Sandesh


People also ask

What is latest Docker tag?

The latest tag is applied by default to reference an image when you run Docker commands without specifying the tag value. The latest tag is applied to the most recent docker build or docker tag command that was run without a tag value explicitly set.

Does Docker tag push?

Functions of Docker Push As we know, we can share images to the public registry or private registry. When we push any image, Docker daemon first checks its tag, how the image is tagged to determine where to push the image.

Can we push Docker image without tagging?

To push an image to a private registry and not the central Docker registry you must tag it with the registry hostname and port (if needed).

How do I add a new tag Docker?

To give tag to a docker file during build command: docker build -t image_name:tag_name . otherwise it will give latest tag to you image automatically. Save this answer.


1 Answers

(About the original version of the question, which used docker push without arguments) docker push will not work unless you provide repository name.

$ docker push
"docker push" requires exactly 1 argument.
See 'docker push --help'.

Usage:  docker push [OPTIONS] NAME[:TAG] [flags]

Push an image or a repository to a registry

That means, you need to push with repository name. And you can either provide TAG or not.

If you do not provide TAG, you are pushing all images for that repository.


In first approach, you are pushing all images under <user>/<image> repository.

In second approach, you are pushing image one by one.

Answer of question

  1. Are both First and Second Option specified above functionally the same?

Both First and Second Option specified above are functionally the same (in your case).

If you do not provide TAG, you are pushing all images for that repository.

In your case

$ docker push <user>/<image>

will push both TAG build_id and latest

  1. Is there any preferred way/Best practice?

I think, second option is better and preferred

Because, you may not want to push all images. In that case, you can choose which image you want to push following second approach.

like image 197
Shahriar Avatar answered Sep 27 '22 22:09

Shahriar