Compose: docker-compose build multiple tags

Created on 29 Jun 2017  路  8Comments  路  Source: docker/compose

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

kinquestion

Most helpful comment

@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

All 8 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DhairyashilBhosale picture DhairyashilBhosale  路  3Comments

dazorni picture dazorni  路  3Comments

darkrasid picture darkrasid  路  3Comments

Hendrik-H picture Hendrik-H  路  3Comments

29e7e280-0d1c-4bba-98fe-f7cd3ca7500a picture 29e7e280-0d1c-4bba-98fe-f7cd3ca7500a  路  3Comments