2

I'm currently trying to make myself familiar with docker but encountered an issue by doing so. I'm trying to share a volume between two containers but I don't want them to put their files into the volumes root.

That's how it should look:

Container1: Mysql has to store /var/lib/mysql/* -> Volume1/mysql

Container2: Ngnix has to store /var/www/* -> Volume1/www

This is how it looks if the containers are created with:

-v Volume1:/var/lib/mysql/ -v Volume1:/var/www/ 

Container1: Mysql has to store /var/lib/mysql/* -> Volume1

Container2: Ngnix has to store /var/www/* -> Volume1

TLDR: I don't to create a volume for the sake of a single file but in order for that to be feasible I have to maintain order in the volume using directorys.

2 Answers 2

2

If I understand correctly, you wanted something like this:

docker run -it --name mysql -v volume/mysql:/mountpoint alpine ash docker run -it --name nginx -v volume/nginx:/mountpoint alpine ash 

But that's not possible. You can not mount a subdirectory of a volume.

If you need that fine-grained control, you'd be better off mounting host directorys just with -v

btw: There is no need for the nginx container to have the mysql files. other way round, mysql does not need the www files. i assume these were just generic examples

0

You can just mount them as -v /path/to/volume1/mysql:/var/lib/mysql and -v /path/to/volume1/www:/var/www

2
  • That's how you mount a host directory, I want to mount a directory of an Volume Commented May 21, 2016 at 11:46
  • I'm not sure what you mean by Volume, then. Could you be more specific? Commented May 24, 2016 at 1:01

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.