How can I include files from outside of Docker\'s build context using the \"ADD\" command in the Docker file?
From the Docker documentation:
T
I spent a good time trying to figure out a good pattern and how to better explain what's going on with this feature support. I realized that the best way to explain it was as follows...
So, with that said, here's an example of the Dockerfile that needs to reuse a file called start.sh
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
Considering this idea, we can think of having multiple copies for the Dockerfiles building specific things, but they all need access to the start.sh
.
./all-services/
/start.sh
/service-X/Dockerfile
/service-Y/Dockerfile
/service-Z/Dockerfile
./docker-compose.yaml
Considering this structure and the files above, here's a docker-compose.yml
shared
context dir is the runtime
dir.
context
. dockerfile
.The docker-compose.yml
is as follows
version: "3.3"
services:
service-A
build:
context: ./all-service
dockerfile: ./service-A/Dockerfile
service-B
build:
context: ./all-service
dockerfile: ./service-B/Dockerfile
service-C
build:
context: ./all-service
dockerfile: ./service-C/Dockerfile
all-service
is set as the context, the shared file start.sh
is copied there as well the Dockerfile specified by each dockerfile
.Cheers!