Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy files from shared directory in multiple Dockerfile?

In my application, I have 5 docker containers and each container starts from images that builds from Dockerfile. Following 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 in the Dockerfile in application 1,2&4. The problem is I have to put the same script.sh in each application directory. Is there any way to use shared folder that contain single script.sh and copy from that? I am using docker-compose to build and run the containers.

like image 359
frodooooo39 Avatar asked Feb 11 '23 09:02

frodooooo39


1 Answers

You could define a container dedicated to keep your script in a volume (as a data volume container)

scripts:
  volumes:
    - /path/to/scripts
application1:
  volumes_from:
    - scripts
application2:
  volumes_from:
    - scripts

The /path/to/scripts folder will be shared in each application.
The scripts Dockerfile should create /path/to/scripts and COPY the script.sh in it.

like image 92
VonC Avatar answered Feb 13 '23 03:02

VonC