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.
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.
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.
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).
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.
(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
- 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
- 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With