0

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):

  • lamp-container
  • data-container

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.

ReynierPM
  • 17,594
  • 53
  • 193
  • 363
  • couldn't you create a `compose.yml` for each user in their respective directory and link based on this ? :: Note I have not done this, just asking. – Pogrindis Sep 21 '16 at 15:35
  • @Pogrindis sorry I am not following you – ReynierPM Sep 21 '16 at 15:36
  • So each container will be running as a different user, changing the `compose.yml` route to be `/home/$USER/compose.yml` and simply using the relative directory structure in the yaml like `./data/logs/` etc ? Just a thought! – Pogrindis Sep 21 '16 at 15:40
  • @Pogrindis still not sure about your solution, will be only a user and that will be mine, at least on my PC. I am trying to build this so others can use the same as well but don't think on multiple users per PC think in one by PC – ReynierPM Sep 21 '16 at 15:43
  • Ahh sorry, I misunderstood the question! Is this related then ? : http://stackoverflow.com/questions/24309526/how-to-change-the-docker-image-installation-directory – Pogrindis Sep 21 '16 at 15:46
  • @Pogrindis no, take a look to the edit I have made to the OP, maybe that clarify where my doubts are. – ReynierPM Sep 21 '16 at 15:54

1 Answers1

2

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.

BMitch
  • 231,797
  • 42
  • 475
  • 450