IuriiO Notebook
  • Broken Code Notebook
  • Architecture and Design
    • Architectural Decision Records
    • Trade-off Analysis
    • Data Decomposition Drivers
    • Selecting a Database Type
    • Service Granularity
    • Consumer-driven Contracts
  • Cloud
    • AWS
      • Resources
      • Compute
        • EC2
        • Batch
        • ECS & ECR
        • Elastic Beanstalk
      • Storage & Data Management
        • S3
        • Storage Gateway
        • RDS
        • DynamoDB
        • ElastiCache
        • Redshift
        • EBS
        • EFS
        • FSx
        • Snowball
        • Athena
        • Encryption and Downtime
        • Untitled
      • Security & Compliance
        • IAM
        • Web Identity Federation
        • Organizations
        • Service Catalog
        • Tags and Resource Groups
        • STS
        • KMS
        • GuardDuty
        • Compliance
        • Marketplace Security Products
        • DDOS
        • Compliance Frameworks
      • High Availability
        • Global Infrastructure
        • Disaster recovery
        • Elastic Load Balancers
        • Untitled
      • Monitoring & Reporting
        • Cost Explorer
        • CloudWatch
        • Systems Manager
        • Config
        • CloudTrail
        • Cost control
        • Untitled
      • Networking
        • Networking 101
        • Route53
        • CloudFront
        • VPC
        • DirectConnect
        • WAF
        • Shield
        • Global Accelerator
      • Deployment & Provisioning
        • Untitled
        • Untitled
      • Automation & Optimization
        • CloudFormation
          • Links
          • Github resources
          • YAML 101
          • Videos
        • OpsWorks
        • Untitled
      • Application Services
        • SQS
        • SWF
        • SNS
        • Untitled
      • Serverless
        • Lambda
        • API Gateway
        • DynamoDB
        • SAM
        • Untitled
      • Well-Architected Framework
    • Azure
      • Tools
      • Organization & Management
      • Authentication & Authorization
      • Compute
      • Networking
      • Storage
      • Databases
      • Security
      • Privacy, Compliance & Trust
      • Cost Management
  • Containers & Services
    • Docker
      • Useful Links
      • Containers
      • Images
      • Dockerfile
      • System
      • Compose
      • Swarm
      • Docker & NodeJS
    • Kubernetes
      • Useful Links
      • Introduction
      • Getting started
      • Exposing containers
      • Kubernetes Management Techniques
        • Declarative YAML
      • Labels and Annotations
      • Storage in Kubernetes
      • Ingress Controller
      • CRD's and The Operator Pattern
      • Kubernetes Dashboard
      • Kubectl Namespaces and Context
  • Frontend
    • Resources
    • Design
      • Search experience
Powered by GitBook
On this page
  • Why
  • Links
  • Example
  • Using compose with build
  • Restart policies

Was this helpful?

  1. Containers & Services
  2. Docker

Compose

Running multiple containers

PreviousSystemNextSwarm

Last updated 5 years ago

Was this helpful?

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.

Links

Example

version: '3'

services:
  drupal:
    image: drupal:8-apache
    ports:
    - '8080:80'
    volumes:
    - drupal-modules:/var/www/html/modules
    - drupal-profiles:/var/www/html/profiles
    - drupal-sites:/var/www/html/sites
    - drupal-themes:/var/www/html/themes
    restart: always
  postgres:
    image: postgres:10
    environment:
      POSTGRES_PASSWORD: pgPass@1
    restart: always

volumes:
  drupal-modules:
  drupal-profiles:
  drupal-sites:
  drupal-themes:

Commands

To start

docker-compose up [--build] [...options]

To tear down

docker-compose down [-v] [...other options]

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

version: '3'

services:
  proxy:
    build:
      context: .
      dockerfile: nginx.Dockerfile
    image: nginx-custom
    ports:
    - '80:80'
  web:
    image: httpd
    volumes:
    - ./html:/usr/local/apache2/htdocs/

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

Compose on GitHub
Compose documentation