Reputation: 18670
I want to setup a data volume container to work together with another LAMP container but I am starting to work with Docker so I have a few doubts around.
So I will two containers running, let's named it as (just as an example):
I know the only way to run multiple containers at once is using Docker Compose but I don't know how to setup the compose.yml
file.
Let's said the lamp-container
has the following directories where it stores data:
/data/www # meant to contain web content
/data/www/default # root directory for the default vhost
/data/logs/ # Nginx, PHP logs
/data/tmp/php/ # PHP temp directories
I want to map all of them separately to a local directory on the host under /home/<username>/container_files
(this is a local directory on the host where docker is running). For example:
/data/www => /home/<username>/container_files/data/www
/data/www/default => /home/<username>/container_files/data/www/default
/data/logs/ => /home/<username>/container_files/data/logs
/data/tmp/php/ => /home/<username>/container_files/data/php
Can any point me on the right direction with a compose.yml
example file? I have read docs but is confusing to me since I am usually used VM and are different from container in some many way.
Note: I should add that this is think for one user in one host not for multiple users in one host. So each person that wants to use this setup should have is own setup under it's host.
Upvotes: 0
Views: 115
Reputation: 264306
Data container volumes have been deprecated with the introduction of named volumes. The named volumes have all the same benefits of a data container, but are managed separately and let you more easily manage the volumes as data and not as a pseudo container.
Here's an example of a docker-compose.yml to mount two named volumes and another network, you'll likely remove most of the lines that don't apply for your own scenario:
version: '2'
volumes:
vol-name-1:
driver: local
vol-name-2:
driver: local
networks:
internal1:
driver: bridge
services:
service-1:
build: .
image: my-service:latest
volumes:
- ./auth:/my-app/auth:ro
- ./host-conf:/my-app/conf
- vol-name-1:/my-app/data-1
- vol-name-2:/my-app/data-2
networks:
- default
- internal1
ports:
- "8080:80"
entrypoint: "my-start.sh"
In the above example, it also mounted two host volumes (bind mounts) and shows how to mount a read only volume with the :ro
on the auth volume.
Upvotes: 2