Home > Blockchain >  Is there a way to create multiple tags using the buildx build command in docker?
Is there a way to create multiple tags using the buildx build command in docker?

Time:07-26

I am trying to use the docker buildx build command and I would like to be able to create multiple tags in one line. An example of what I have tried

docker buildx build . \
    --platform linux/arm64,linux/amd64 \
    --no-cache --push \
    -t test:latest -t test:${CI_COMMIT_SHORT_SHA}

I have seen this issue, but I haven't been able to get it to work https://github.com/docker/buildx/issues/396

CodePudding user response:

It works exactly as you've posted with multiple -t args, e.g. -t repo1:tag1 -t repo2:tag2:

$ regctl tag ls sudobmitch/demo
alpine
regcli-test
regctl
ubuntu

$ docker buildx build -f build/Dockerfile.regctl.buildkit -t sudobmitch/demo:regctl1 -t sudobmitch/demo:regctl2 --push .
[ ] Building 13.4s (24/24) FINISHED                                                                          
 => [internal] load build definition from Dockerfile.regctl.buildkit                                    0.0s
 => => transferring dockerfile: 4.40kB                                                                  0.0s
 => [internal] load .dockerignore                                                                       0.0s
 => => transferring context: 172B                                                                       0.0s
 => resolve image config for docker.io/docker/dockerfile:1                                              0.3s
 => [auth] docker/dockerfile:pull token for registry-1.docker.io                                        0.0s
 => CACHED docker-image://docker.io/docker/dockerfile:1@sha256:443aab4ca21183e069e7d8b2dc68006594f40bd  0.0s
 => => resolve docker.io/docker/dockerfile:1@sha256:443aab4ca21183e069e7d8b2dc68006594f40bddf1b15bbd83  0.0s
 => [internal] load metadata for docker.io/library/golang:1.17-alpine                                   0.4s
 => [auth] library/golang:pull token for registry-1.docker.io                                           0.0s
 => [golang 1/4] FROM docker.io/library/golang:1.17-alpine@sha256:3bdce0a4828648811dc3ac155b8f5155ca6e  0.0s
 => => resolve docker.io/library/golang:1.17-alpine@sha256:3bdce0a4828648811dc3ac155b8f5155ca6e13c5a86  0.0s
 => [internal] load build context                                                                       0.2s
 => => transferring context: 8.95MB                                                                     0.2s
 => CACHED [golang 2/4] RUN apk add --no-cache       ca-certificates       git       make               0.0s
 => CACHED [golang 3/4] RUN addgroup -g 1000 appuser  && adduser -u 1000 -G appuser -D appuser  && mkd  0.0s
 => CACHED [golang 4/4] WORKDIR /src                                                                    0.0s
 => [dev 1/1] COPY --link . /src/                                                                       0.3s
 => [build 1/1] RUN --mount=type=cache,id=gomod,target=/go/pkg/mod/cache     --mount=type=cache,id=gor  1.5s
 => CACHED [release-scratch 1/5] ADD  --link build/root.tgz /                                           0.0s
 => CACHED [release-scratch 2/5] COPY --link --from=build /etc/passwd /etc/group /etc/                  0.0s
 => CACHED [release-scratch 3/5] COPY --link --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/  0.0s
 => CACHED [release-scratch 4/5] COPY --link --from=build --chown=1000:1000 /home/appuser/ /home/appus  0.0s
 => [release-scratch 5/5] COPY --link --from=build /src/bin/regctl /regctl                              0.0s 
 => exporting to image                                                                                  3.7s 
 => => exporting layers                                                                                 0.4s
 => => exporting manifest sha256:ebd28e5f9096008ce106880bea389dfaf164cd298429705ccb922fd72142f83c       0.0s
 => => exporting config sha256:5fc50e1c198eb9061de9f0c1a12cb660753c41b46d1eb73f6117e3e260ba641d         0.0s
 => => pushing layers                                                                                   0.2s
 => => pushing manifest for docker.io/sudobmitch/demo:regctl1@sha256:ebd28e5f9096008ce106880bea389dfaf  0.2s
 => => pushing manifest for docker.io/sudobmitch/demo:regctl2@sha256:ebd28e5f9096008ce106880bea389dfaf  0.1s
 => [auth] sudobmitch/demo:pull,push token for registry-1.docker.io                                     0.0s
 => [auth] sudobmitch/demo:pull,push token for registry-1.docker.io                                     0.0s
 => [auth] sudobmitch/demo:pull,push token for registry-1.docker.io                                     0.0s
 => [auth] sudobmitch/demo:pull,push token for registry-1.docker.io                                     0.0s

$ regctl tag ls sudobmitch/demo
alpine
regcli-test
regctl
regctl1
regctl2
ubuntu

This is assuming test was an example in your question. If you actually tried to push to the test repo, that expands to Docker Hub's Library, along side other official images like alpine, busybox, debian, etc. You don't have access to push there, so make sure to point to a repository where you have access to push images and have logged in.

  • Related