Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-compose build error when using parent dir & dockerfile for build

I have the following structure:

. .. docker/cli/Dockerfile tests/docker-compose.yml docker-compose.yml 

In my tests/docker-compose.yml I have the following service defined:

services:   test:     build:       context: ../       dockerfile: ../docker/cli/Dockerfile   ... 

When do a docker-compose build I get:

Building test ERROR: Forbidden path outside the build context: ../docker/cli () 
like image 526
ddinchev Avatar asked May 08 '16 10:05

ddinchev


People also ask

How do I force recreate docker compose?

If you want to force Compose to stop and recreate all containers, use the --force-recreate flag. If the process encounters an error, the exit code for this command is 1 . If the process is interrupted using SIGINT (ctrl + C) or SIGTERM , the containers are stopped, and the exit code is 0 .

Can Dockerfile copy files from parent directory?

It turns out that you cannot include files outside Docker's build context. However, you can copy files from the Dockerfile's parent directory.

Does docker compose use Buildkit?

docker compose does not use current buildkit builder #8531.

How do I put files outside docker's build context?

The best way to work around this is to specify the Dockerfile independently of the build context, using -f. For instance, this command will give the ADD command access to anything in your current directory. docker build -f docker-files/Dockerfile . docker build -f ../Dockerfile .


1 Answers

After I wrote the question I actually found the problem. When you define a context in docker-compose, the dockerfile: bit is relative to that context. So the proper configuration would be:

  test:     build:       context: ../       dockerfile: docker/cli/Dockerfile 

I hope this helps someone...

like image 182
ddinchev Avatar answered Sep 18 '22 21:09

ddinchev