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 ()
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 .
It turns out that you cannot include files outside Docker's build context. However, you can copy files from the Dockerfile's parent directory.
docker compose does not use current buildkit builder #8531.
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 .
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With