How do I copy files from a shared directory to multiple Dockerfiles?
In my application, I have 5 docker containers and each container starts with images that are built from the Dockerfile. Below is the structure:
-projectdir
-docker
-application1
-Dockerfile
-script.sh
-application2
-Dockerfile
-script.sh
-application3
-Dockerfile
-application4
-Dockerfile
-script.sh
-application5
-Dockerfile
script.sh is copied to Dockerfile in app 1,2 and 4. The problem is I have to put the same script.sh in every app directory. Is there a way to use a shared folder containing a single script.sh and copy from it? I am using docker-compose to build and run containers.
source to share
You can define a container designed to hold the script in volume (as a container for the amount of data )
scripts:
volumes:
- /path/to/scripts
application1:
volumes_from:
- scripts
application2:
volumes_from:
- scripts
The folder /path/to/scripts
will be used in every application.
File scripts
Dockerfile must create /path/to/scripts
and COPY script.sh
it.
source to share
As of Docker 1.5, you can specify the path in the build context for the Dockerfile. So, the following works:
-projectdir
-docker
-script.sh
-application1
-Dockerfile
-application2
-Dockerfile
...
You can create with:
$ cd docker
$ docker build -f application1/Dockerfile .
Unfortunately I don't think you can do this with Compose, so you might have to use a separate script to create and label your images, which you can then use in Compose.
source to share