Junior — Middle
How can you create a single Docker image with multiple tags when working with GitLab CI/CD?
sobes.tech AI
Answer from AI
In GitLab CI/CD, to create a single Docker image with multiple tags, it is common to use the docker build command with one tag, and then use the docker tag command to add additional tags to the same image. Afterwards, all tags can be pushed to the registry.
Example in .gitlab-ci.yml:
build:
stage: build
script:
- docker build -t myimage:latest .
- docker tag myimage:latest myimage:1.0.0
- docker tag myimage:latest myimage:stable
- docker push myimage:latest
- docker push myimage:1.0.0
- docker push myimage:stable
Thus, the image is built once, and then it is assigned multiple tags, which are then pushed to the registry.