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?
答案 0 :(得分:5)
First of all
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.
After question modification
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. 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
_2. 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.