Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker compose, it is possible to mount a folder inside an already mounted volume?

Tags:

When using compose for development I have my app mounted inside /var/www/html with this:

volumes:
- ./app:/var/www/html

My local copy needs all the images that are in the production website, that are quite a lot so I don't want to store them in my tiny ssd but in a big extenal disk.

So my images are located in my /media/storage/bigdisk/images.

it is possible to mount this location inside the already mounted /var/www/html?

This way doesn't seem to work:

volumes:
  - ./app:/var/www/html
  - /media/storage/bigdisk/images:/var/www/html/images
like image 593
Mir Avatar asked Oct 16 '17 15:10

Mir


1 Answers

This should work normally, the only downside of this solution is that docker will create additional directory in ./app/images - so it can mount images volume.

For this directory tree:

- app
--- index.php
- docker-compose.yml
- media
--- picture.png

And docker-compose.yml:

version: '2'

services:
  app:
    image: ubuntu
    volumes:
      - ./app:/var/www/html
      - ./media:/var/www/html/images

You get:

$ docker-compose run --rm app find /var/www/html
/var/www/html
/var/www/html/index.php
/var/www/html/images
/var/www/html/images/picture.png

This works even when ./app/images directory is present locally with some content. If it not exists then docker creates empty directory there with root:root persmission (if container runs as root).

Tested on Docker version 1.12.6 and docker-compose version 1.8.0

like image 154
Paweł Tatarczuk Avatar answered Oct 11 '22 14:10

Paweł Tatarczuk