I was wondering if it is possible to build docker images using docker-compose file with multiple tags?
version: '2.2'
services:
foo:
build:
context: .
dockerfile: Dockerfile
args:
CT_TAG: 6.10
labels:
com.example.description: "Accounting webapp"
image: foo:baz
image: foo:bar
This will only tag the image as foo:bar
and not foo:baz
No, that is not currently possible.
See this answer on StackOverflow for a couple of possible work-arounds to this issue.
@dirkschneemann Thanks. I ended up writing a small script to do it.
@Puneeth-n - you can do this natively in docker-compose as follows:
services:
# build is your actual build spec
build:
image: myrepo/myimage
build:
context: .
...
...
# these extend from build and just add new tags statically or from environment variables
version_tag:
extends: build
image: myrepo/myimage:v1.0
some_other_tag:
extends: build
image: myrepo/myimage:${SOME_OTHER_TAG}
With the above in place, you can then just run docker-compose build
and docker-compose push
and you will build and push the correct set of tagged images
@mixja awesome! :) Thanks :)
@mixja, the extends keyword is not supported from 3.x :-(
https://docs.docker.com/compose/compose-file/#extension-fields
Extension fields and YAML anchors is a decent alternative in v3 to the v2 extends
.
For an example on how to use the weird syntax of YAML anchors, have a lok at https://stackoverflow.com/questions/47327979/how-to-use-multiple-image-tags-with-docker-compose/59911532#59911532
Most helpful comment
@Puneeth-n - you can do this natively in docker-compose as follows:
With the above in place, you can then just run
docker-compose build
anddocker-compose push
and you will build and push the correct set of tagged images