3

Here is a sample symfony project:

my_project:
    assets:
    src:
    web:
    package.json
    composer.json

I have an apache container and a container with webpack that will be used to watch the assets folder and build it when something changes.

As both containers need access to the same filesystem, let's say I:

  • Create a named volume
  • Copy my_project in it using this technique
  • Run some composer install and npm install commands

Once everything is ready, I need the apache container to share the src folder with the host and the webpack container to share the assets folder with the host.
That way, everytime I change a file in those folders, I would be able to see the result in my browser.

I saw that it's not possible for the moment to mount subdirectories so what other way is there?
Or am I thinking about it the wrong way?

MrVoodoo
  • 1,042
  • 1
  • 15
  • 25

1 Answers1

1

Since mounting subdirectories of named volumes is not a possibility, maybe you can try the following.

As I see it, multiple containers need access to the same filesystem. According to the docker volume docs:

Remember that multiple containers can mount the same volume, and it can be mounted read-write for some of them and read-only for others, at the same time.

So essentially, you can create a single docker volume and share it between all your containers:

# Initialize the Docker Volume
docker volume create my_project_volume
docker run -v my_project_volume:/my_project --name helper alpine true
docker cp . helper:/my_project
docker rm helper

If you want your applications (such as apache) to only access subfolders within your volume, you can always mount the volume to / (or anywhere of your choosing), and create a symlink from the directory your application will access to the volume subdirectory. For example:

# 1. Run your apache container, mounting the named volume to root dir
docker run -v my_project_volume:/my_project --name my_apache httpd:latest

# 2. Create symlink to named volume subdirectory
docker exec -it my_apache ln -s /usr/local/apache2/htdocs /my_project/src
moebius
  • 2,061
  • 11
  • 20