Problem using volume in several containers

Hi,

I’m quite new to docker. Although that I just started I’d like to setup all needed stuff with docker. And I want to follow the docker philosophy of one command per container. But there is currently one thing I don’t understand.

I’ve started with a simple webserver + database: nginx, phpfpm, mysql and phpmyadmin in separate containers.
I’m using docker-compose.

wwwdata:
build: ./wwwdata
restart: always
volumes:
- ./data/var/www:/var/www
mysql:
build: ./mysql
restart: always
environment:
- MYSQL_ROOT_PASSWORD=xxxxx
volumes:
- /etc/localtime:/etc/localtime:ro
- ./data/var/log/mysql:/var/log/mysql
- ./data/var/lib/mysql:/var/lib/mysql
phpmyadmin:
build: ./phpmyadmin
restart: always
volumes_from:
- wwwdata
links:
- mysql:mysql
phpfpm:
build: ./phpfpm
restart: always
volumes:
- /etc/localtime:/etc/localtime:ro
- ./data/var/log/php5-fpm:/var/log/php5-fpm
volumes_from:
- wwwdata
nginx:
build: ./nginx
restart: always
ports:
- “80:80”
- “443:443”
volumes:
- /etc/localtime:/etc/localtime:ro
- ./data/var/log/nginx:/var/log/nginx
volumes_from:
- wwwdata
links:
- phpfpm:phpfpm

So I’m having the wwwdata container which only has the /var/www directory which is also used in nginx, phpfpm and phpmyadmin is stored there (there are maybe better ways but I’d like to figure out what I’m doing wrong). So in the phpmyadmin Dockerfile I’m downloading und unzippin phpmyadmin and then store it to /var/www/phpmyadmin. Unfortunately I cannot see phpmyadmin in /var/www from other containers or from my host system. And I cannot even see it inside the phpmyadmin container although I’ve created it there. When I’m not creating /var/www as volume I can at least see phpmyadmin in the phpmyadmin container. So my resolution for now is: Create phpmyadmin installation somewhere else, use an entrypoint script and, if /var/www/phpmyadmin does not exist, move it there, so it is in the volume afterwards. I guess there is a better way, right? I thought files which are alreay existing in an image will still be there if I create a volume at this place? Isn’t that right?

It sounds like you are putting the phpmyadmin files into the /var/www/phpmyadmin folder in the container’s filesystem. A volume is effectively a mountpoint. Just like a normal filesystem mount process, anything in the directory that you mount will effectively be hidden.

You have a couple of choices. You could put phpmyadmin into the /var/www volume at some point during a container’s runtime (probably startup).

Another approach might be to simply put phpmyadmin somewhere else in the container’s filesystem. If phpmyadmin is a standalone container that runs phpmyadmin, you could even drop the /var/www volume altogether.

/Jeff