Junior — Middle
How can you configure a CI/CD pipeline to build a Docker image with multiple tags simultaneously?.
sobes.tech AI
Answer from AI
To build a Docker image with multiple tags simultaneously in a CI/CD pipeline, the docker build command is usually used with multiple -t parameters. For example, in GitLab CI or GitHub Actions, you can specify a step where the image is built and immediately tagged with multiple tags:
docker build -t myimage:latest -t myimage:v1.0 -t myimage:commit-${CI_COMMIT_SHA} .
This allows creating an image with different tags in one command, which is convenient for different environments or versions. You can also use environment variables in the pipeline to dynamically generate tags.
If docker buildx is used, multiple tags are also supported via --tag or -t.
Thus, the key point is to specify all necessary tags in the build command using repeated -t parameters, to avoid doing multiple separate builds.