18

When I build image in CI I push it with a unique SHA tag. Then when I deploy it to production I want to change :latest alias to point to the same image like so:

docker pull org/foo:34f8a342
docker tag org/foo:34f8a342 org/foo:latest
docker push org/foo:latest

Now I want to avoid pulling this image. The problem is that container for deploy script is different from container that was used to build it so I don't have this image locally. Is there any way to add a tag alias on docker hub without the need to have this image locally?

Poma
  • 8,174
  • 18
  • 82
  • 144
  • 1
    A discussion about this use-case here: https://forums.docker.com/t/tag-without-pull-push/12836/10 became the rest-of-the-world commonsense vs DockerHub. – Ed Randall Feb 22 '20 at 12:40

4 Answers4

14

Using the experimental docker manifest command:

docker manifest create $REPOSITORY:$TAG_NEW $REPOSITORY:$TAG_OLD
docker manifest push $REPOSITORY:$TAG_NEW

For a private registry, you may need to prepend $REGISTRY/ to the repository.

mabraham
  • 2,806
  • 3
  • 28
  • 25
  • 2
    And if you already have `$TAG_NEW` tag in your repository don't forget to use the `--amend` command line option for `docker manifest create`. – andr Mar 26 '23 at 13:20
5

As it can be seen here its not allowed, but if the problem is that pulling the entire image is slow as someone mentions in the comments it can be acheived faster just "pulling" the manifest as here through the Docker Registry API

MANIFEST=$(curl -H "Accept: application/vnd.docker.distribution.manifest.v2+json" "${REGISTRY_NAME}/v2/${REPOSITORY}/manifests/${TAG_OLD}")
curl -X PUT -H "Content-Type: application/vnd.docker.distribution.manifest.v2+json" -d "${MANIFEST}" "${REGISTRY_NAME}/v2/${REPOSITORY}/manifests/${TAG_NEW}"
Angel Tabares
  • 333
  • 4
  • 10
1

I'm not aware of tagging a docker image directly on docker hub. There's a workaround for your problem, that is tagging the image with two tags when building it. docker build allows to create multiple tags for one build:

docker build -t org/foo:34f8a342 -t org/foo:latest .
dvnguyen
  • 2,954
  • 17
  • 24
  • 5
    But at the moment of build I don't yet want to upload this image with `:latest` tag, I want to deploy it to staging and test first. So the second tag will be lost since build machine is destroyed immediately after build is finished. – Poma Jan 21 '18 at 21:28
  • 1
    Did you ever find a solution? We are going to do the same thing. We could pull and tag, but pulling is slow. – GreenKiwi Jun 23 '18 at 06:21
0

In my case, I had to add an extra tag to an existing multi arch image. Docker tag would not work, because it would pull and tag only the image matching my OS.

I didn't want to use docker buildx imagetools create again because it would create a new imageIndex.

I used Skopeo copy command.

skopeo --multi-arch=index-only copy docker://<IMAGE>:<TAG> docker://<IMAGE>:<NEW TAG>
Thiago
  • 864
  • 1
  • 9
  • 16