I have a docker image with three tags repo:latest, repo:v1.1, repo:dev. When I do docker push repo:v1.1 only one tag will be pushed into repository. Is there a way to make one push with all tags or I need to push-per-tag?
I have a docker image with three tags repo:latest, repo:v1.1, repo:dev. When I do docker push repo:v1.1 only one tag will be pushed into repository. Is there a way to make one push with all tags or I need to push-per-tag?
The docker push command does not accept several arguments (if ever one wants to push a selection of several tags (not all) in one go), so one needs to push each tag separately, e.g.:
for t in latest v1.1 dev; do
docker push "repo:${t}"
done
Otherwise, as mentioned in @GuillaumePancak's answer, one may be interested in relying on the --all-tags flag available from Docker 20.10.0.
Note also that it is frequent to consider pushing several different tags for the same image (which may be your use case here as well). In this case pushing these tags successively (and not at the same time with several concurrent processes) ensures the docker push of the tag synonyms will be almost immediate, after the image has been pushed once with a given tag.
If you want to push all tags for an image, you can use the --all-tags option:
docker image push --all-tags repository/image_name
This option is supported for Docker 20.10 and newer. The same behaviour can be achieved by omitting --all-tags on older versions.
More information: Docker push documentation
There is currently a change to push multiple image in the same time, which is in review.
But it only adds a loop for the docker push instead of parallelizing them.
So right now, the unique solution is to push each tag separately.
I had a similar situation and was able to solve it like this:
In my examples I will be using elonmusk/spacerocket as an example repository name. You should replace this with your
name/repo.
# First I build and tag my image:
docker build --tag elonmusk/spacerocket:tag-1 --tag elonmusk/spacerocket:tag-2 --tag elonmusk/spacerocket:flymetothemoon .
Which gives this output after running docker images
(I've left out CREATED and SIZE from this table)
REPOSITORY TAG IMAGE ID
elonmusk/spacerocket tag-1 1a4acbyb12db
elonmusk/spacerocket tag-2 1a4acbyb12db
elonmusk/spacerocket flymetothemoon 1a4acbyb12db
Now when I execute docker push elonmusk/spacerocket without any tags, it will push all the tags for me.
# First I build my image:
docker build -t thiscouldbewhatever . # -t is shorthand for --tag
Which gives this output:
REPOSITORY TAG IMAGE ID
thiscouldbewhatever latest 1a4acbyb12db
And now I start tagging:
docker tag thiscouldbewhatever elonmusk/spacerocket:tag-1
docker tag thiscouldbewhatever elonmusk/spacerocket:tag-2
docker tag thiscouldbewhatever elonmusk/spacerocket:tag-3
docker tag thiscouldbewhatever elonmusk/spacerocket:whystopatthemoon
And finally push all my tags:
# push the repo without using a tag.
docker push elonmusk/spacerocket
# Just to be double clear, this will only push one tag:
docker push elonmusk/spacerocket:tag-1
in a script you can do a loop like this to push all tags for an image; ${1} is the first parameter passed to the script; like docker_push myimage
for i in $(docker image list --format "{{.Tag}}" "${1}"); do
docker push "${1}:$i"
done