Docker 'latest' Tagging and Pushing

10,702

(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.

Share:
10,702

Related videos on Youtube

Sandesh
Author by

Sandesh

Updated on June 04, 2022

Comments

  • Sandesh
    Sandesh almost 2 years

    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?
  • lindhe
    lindhe over 3 years
    "If you do not provide TAG, you are pushing all images for that repository." can anyone find a reference on this? I cannot find it in the official docs for Docker...
  • Shahriar
    Shahriar over 3 years
    docker push --help : Push an image or a repository to a registry
  • lindhe
    lindhe over 3 years
    what version of Docker do you have? I'm at 19.03.6 and the help text for the push command is very sparse and mentions nothing about what images gets pushed if TAG is not provided.
  • timguy
    timguy about 2 years
    I am also confused if all tags are pushed if nothing is given what is "--all-tags" ("Push all tagged images in the repository") parameter for. docs.docker.com/engine/reference/commandline/push But maybe it depends on docker version.