notes.dt.in.th

Remotely re-tagging a Docker image

::: lead tl;dr: docker buildx imagetools create $SOURCE --tag $TARGET :::

  • Some managed app platform provides the ability to deploy images simply by pushing a Docker image to a predefined tag.

  • For example, DigitalOcean’s App Platform has this option:

  • Usually one might do a docker pull && docker push in a deployment pipeline, but it’s a waste of bandwidth:

    SOURCE=registry.tld/service:commit-abcdef
    TARGET=registry.tld/service:staging
    
    docker pull $SOURCE
    docker tag $SOURCE $TARGET
    docker push $TARGET
    • Also, if the image is multi-platform, only the current platform will be retagged. This may be problematic if your CI runs on Intel but the deployment target runs on ARM e.g. Ampere or Graviton.

    • On some registries, they provide a CLI command to re-tag an image, but it’s specific to that platform. e.g. Amazon ECR, GCR.

  • Thanks to Francois Nel’s StackOverflow answer on the question “Add remote tag to a docker image”, now I know we can do this:

    SOURCE=registry.tld/service:commit-abcdef
    TARGET=registry.tld/service:staging
    
    docker buildx imagetools create $SOURCE --tag $TARGET

    And it supports multi-platform images!