Compose
Running multiple containers

Why

    Configure relationships between containers
    Save docker container run settings in easy-to-read file
    create one-liner development environment startups
Comprised of 2 separate but related things:
    YAML formatted file that describes solution options for:
      containers
      volumes
      networks
    A CLI tool docker-compose used for local dev/test automation
Installed automatically on Mac and Windows with Docker Desktop, for Linux must be downloaded separately.

Example

1
version: '3'
2
3
services:
4
drupal:
5
image: drupal:8-apache
6
ports:
7
- '8080:80'
8
volumes:
9
- drupal-modules:/var/www/html/modules
10
- drupal-profiles:/var/www/html/profiles
11
- drupal-sites:/var/www/html/sites
12
- drupal-themes:/var/www/html/themes
13
restart: always
14
postgres:
15
image: postgres:10
16
environment:
17
POSTGRES_PASSWORD: [email protected]
18
restart: always
19
20
volumes:
21
drupal-modules:
22
drupal-profiles:
23
drupal-sites:
24
drupal-themes:
25
Copied!
Commands
To start
1
docker-compose up [--build] [...options]
Copied!
To tear down
1
docker-compose down [-v] [...other options]
Copied!

Using compose with build

    compose can also build your images
    will build them with docker-compose up if not found in cache
    also rebuild with docker-compose build
    great for complex builds that have lots of vars or build args
Example
1
version: '3'
2
3
services:
4
proxy:
5
build:
6
context: .
7
dockerfile: nginx.Dockerfile
8
image: nginx-custom
9
ports:
10
- '80:80'
11
web:
12
image: httpd
13
volumes:
14
- ./html:/usr/local/apache2/htdocs/
Copied!

Restart policies

    "no" - never attempt to restart this container if it stops or crashes (must be in "")
    always - if this container stops, for any reason, always attempt to restart it
    on-failure - only restart if the container stops with an error code
    unless-stopped - always restart unless we forcibly stop it
Last modified 1yr ago