In my Maven project I have following structure:
docker/
docker-compose.yml
A/
Dockerfile
B/
Dockerfile
src/
target/
foo.war
In A's Dockerfile I need access to war in /target
folder with the following command:
COPY ../../target/foo.war /usr/local/tomcat/webapps/foo.war
when I run docker-compose up
tt gives me error
failed to build: COPY failed: Forbidden path outside the build context: ../../target/foo.war
docker-compose.yml
version: '3.6'
services:
fooA:
build: ./docker/A
ports:
- "8080:8080"
depends_on:
- fooB
fooB:
build: ./docker/fooB
ports:
- "5433:5433"
Can you tell me how to solve this? I don't want copy war file manually after every project build.
Suppose you have the following dir structure
./docker-compose.yaml
./all-runners/
/start.sh
/runner-A/Dockerfile
/runner-B/Dockerfile
/runner-C/Dockerfile
It ALWAYS
will load from its relative path, having the current dir of itself as the local
reference to the paths you specify.
COPY start.sh /runtime/start.sh
shared
context dir is the runtime
dir.
context
. dockerfile
.The docker-compose.yml
is as follows
version: "3.3"
services:
runner-A
build:
context: ./all-runners
dockerfile: ./runner-A/Dockerfile
runner-B
build:
context: ./all-runners
dockerfile: ./runner-B/Dockerfile
runner-C
build:
context: ./all-runners
dockerfile: ./runner-C/Dockerfile
all-runners
, the file start.sh
will be reuse by each individual Dockerfile specified by the path in dockerfile
.Now your build works with files outside the dir of your Dockerfile
. The result is just the same when you do the proper mapping!
Happy Dockering 🐳!
As far as I know it's not possible to access things outside out your build context.
You might have some luck by mixing the dockerfile
directive with the context
directive in your compose file in the root dir of your project as follows:
build:
context: .
dockerfile: A/Dockerfile
You may wish to include a .dockerignore
in the project root dir to prevent the entire project being send to the docker daemon resulting in potentially much slower builds.
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