2

This question seems to have a simple answer on the surface "volumes" although I believe it may be more complex then that.

Explanation

We have three services, each of these services can have many containers running across the single or multiple hosts.

Container A is our API container

Container B is our queue container

Container C is our task-schedule (cron) container

All these containers are running off the same git-repo / source code (PHP). The only difference is the process that is running within containers:

Container A is running php-fpm

Container B is running a queue monitoring daemon (artisan queue)

Container C is running crontab that executes any cron tasks

At present in the dockerfile for each "service" we download the git repo and boot up the relevant process. Although it would be better to have a "data" container that somehow serves the code to all the above mentionsed containers.

QUESTION

How can we create a container that acts as a "code repository" for other containers? Mounting the source files from its file system into the file systems of other "service" containers?

migrated from stackoverflow.com Aug 17 '16 at 6:48

This question came from our site for professional and enthusiast programmers.

1

The preferred way to do this is with a named volume:

version: '2'

volumes:
  data:
    driver: local

services:
  service-1:
    build: .
    image: my-service:latest
    volumes:
      - data:/data

  service-2:
    image: my-service:latest
    volumes:
      - data:/data

To use a data container, you need to have volumes on that container and then mount those with the volumes-from in the other containers:

version: '2'

services:
  data:
    build: .
    image: my-service:latest
    command: /bin/true
    volumes:
      - /data

  service-1:
    image: my-service:latest
    volumes-from:
      - data

  service-2:
    image: my-service:latest
    volumes-from:
      - data

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy