Compose: build: "Cannot locate specified Dockerfile" when Dockerfile is valid symlink

Created on 26 Oct 2017  路  2Comments  路  Source: docker/compose

When a Dockerfile in a build block is a valid symlink to a valid file, docker-compose build is not able to find it:

docker-compose.yml:

version: '2'
services:
  app:
    build:
      context: docker/app
ls -l docker/app/
total 8
lrwxr-xr-x  1 ej  1342  40 Oct 26 12:41 Dockerfile@ -> ../../eol_xras_aux/docker/app/Dockerfile
cat docker/app/Dockerfile
# ... content of ../../eol_xras_aux/docker/app/Dockerfile
docker-compose build
Building app
ERROR: Cannot locate specified Dockerfile: Dockerfile

Same behavior when using full path for symlink

ls -l docker/app/
total 8
lrwxr-xr-x  1 ej  1342  76 Oct 26 13:07 Dockerfile@ -> /Users/ej/Dropbox/NCAR/presto/xras_submit/eol_xras_aux/docker/app/Dockerfile

Same behavior w/ 1.14.0, 1.16.1 and 1.17.0-rc1, all on Darwin, as well as Compose-file format versions 2 => 3.2.

kinquestion

Most helpful comment

Yes, you can't link to a Dockerfile outside of the build context. This is intended and matches docker build's behavior:

$ ls -l docker/app/
total 0
lrwxrwxrwx 1 shin shin 14 Oct 26 13:08 Dockerfile -> ../../Dakafile
$ docker build docker/app
unable to prepare context: the Dockerfile () must be within the build context
$ docker-compose build
Building baz
ERROR: Cannot locate specified Dockerfile: Dockerfile

Our error message could be better though.

All 2 comments

Yes, you can't link to a Dockerfile outside of the build context. This is intended and matches docker build's behavior:

$ ls -l docker/app/
total 0
lrwxrwxrwx 1 shin shin 14 Oct 26 13:08 Dockerfile -> ../../Dakafile
$ docker build docker/app
unable to prepare context: the Dockerfile () must be within the build context
$ docker-compose build
Building baz
ERROR: Cannot locate specified Dockerfile: Dockerfile

Our error message could be better though.

Oh, right, thanks!

Was this page helpful?
0 / 5 - 0 ratings