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.
Dir Structure
Suppose you have the following dir structure
Dockerfile
It
ALWAYS
will load from its relative path, having the current dir of itself as thelocal
reference to the paths you specify.Docker-compose
shared
context dir is theruntime
dir.context
.dockerfile
.The
docker-compose.yml
is as followsall-runners
, the filestart.sh
will be reuse by each individual Dockerfile specified by the path indockerfile
.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 thecontext
directive in your compose file in the root dir of your project as follows: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.You can structure your project to have your Compose file and Dockerfile in directory tree like yours. You need to change your Compose file to support this, like this:
You can then build this set up with
docker-compose -f docker/docker-compose.yml build
.