Compose: Build target doesn't work in compose 1.19

Created on 26 Feb 2018  路  6Comments  路  Source: docker/compose

I have the following in docker-compose.yml:

version: '3'
services:
  app:
    build:
      context: .
      target: app

I'm using docker-compose version 1.19.0, build 9e633ef installed via pip3.

After running docker-compose build the expected result is to have the container for app service build with --target docker argument set to app.

The actual result is

ERROR: The Compose file './docker-compose.yml' is invalidbecause:
services.app.build contains unsupported option: 'target'

Related issues

I've found this issue https://github.com/docker/compose/issues/5322 which states in comments that the build target is supported since 1.17.

Also, I've found this issue https://github.com/docker/docker.github.io/issues/6036 which states that the syntax is the same as for 2.x compose file version.

Most helpful comment

The issue was I've used version 3 which is not the latest from 3.x series as I thought. One needs to use at least version 3.4 for build target to work.

All 6 comments

The issue was I've used version 3 which is not the latest from 3.x series as I thought. One needs to use at least version 3.4 for build target to work.

Just wanted to say thanks for this, for some reason I assumed if you put '3' as the version type, it would default to the latest supported version of '3' your docker client supports, but I was wrong. Doing the steps above, in my case, 3 -> 3.7 worked. ^^

Also pretty confusing for me, since this is documented in version 2 as well. I assumed that if it was available in 2.3 then naturally it'd also automatically be available in 3. Turns out that's not the case, for some reason.

The issue was I've used version 3 which is not the latest from 3.x series as I thought. One needs to use at least version 3.4 for build target to work.

Same error at 3.7.4

D:\WORK\Projects\api>docker-compose version
docker-compose version 1.25.5, build 8a1c60f6
docker-py version: 4.1.0
CPython version: 3.7.4
OpenSSL version: OpenSSL 1.1.1c  28 May 2019

D:\WORK\Projects\api>docker-compose up
ERROR: The Compose file '.\docker-compose.yml' is invalid because:
services.api.build contains unsupported option: 'target'
services.synchronizer.build contains unsupported option: 'target'

@akopchinskiy in this case the version is in reference to the version of the YAML content not necessarily the version of docker-compose that you have instead.

Specifically: Did you try editing docker-compose.yml so that the first line version: '3' reads version: '3.7' instead?

@patricknelson

Did you try editing docker-compose.yml so that the first line version: '3' reads version: '3.7' instead?

I did try and it's working. Thank you!

Was this page helpful?
0 / 5 - 0 ratings