Skip to content

Latest commit

 

History

History
120 lines (78 loc) · 3.5 KB

File metadata and controls

120 lines (78 loc) · 3.5 KB

Docker Compose

Table of contents

What is Docker Compose

Docker Compose runs multi-container apps from a docker-compose.yml file.

Example of the file: docker-compose.yml.

See also:

docker-compose.yml

Service

A service is a named entry under the services: key in docker-compose.yml. It defines how to build or pull an image and run it as a container.

For example, this project defines four services in docker-compose.yml: app, postgres, pgadmin, and caddy.

Service name

Docker Compose networking

Docker Compose creates a network where services can reach each other by their service name.

Docs:

Volume

A volume is persistent storage managed by Docker. Data in a volume survives container restarts.

Volumes are defined in docker-compose.yml:

volumes:
  postgres_data:

A service can mount a volume to store data:

services:
  postgres:
    volumes:
      - postgres_data:/var/lib/postgresql/data

Health checks

A health check is a command that Docker runs periodically to check if a container is healthy.

Other services can wait for a container to be healthy before starting:

services:
  app:
    depends_on:
      postgres:
        condition: service_healthy

  postgres:
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s
      timeout: 5s
      retries: 5

Actions

Stop and remove all containers

  1. To stop all running services and remove containers,

    run in the VS Code Terminal:

    docker compose --env-file .env.docker.secret down
    

Stop and remove all containers and volumes

  1. To stop all running services, remove containers, and remove volumes,

    run in the VS Code Terminal:

    docker compose --env-file .env.docker.secret down -v
    

Stop and remove all containers, volumes, and images

  1. To stop all running services, remove containers, remove volumes, and remove images,

    run in the VS Code Terminal:

    docker compose --env-file .env.docker.secret down -v --rmi all