Introduction to Compose

Collin Dewey

02/20/2025

Compose

Docker/Podman Compose


What is Compose?

Managing multiple containers at a time. Managing multiple networks at a time.


Why use it over regular Docker or Kubernetes?

Kubernetes has lots of features that many people just don’t need. Running a bunch of different CLI commands for managing multiple containers is a pain.


What is in compose.yml

YAML Formatted File with definitions of…


Services 1


Service Example

services:
  hugo:
    container_name: hugo
    image: klakegg/hugo
    command: --watch --destination /dest
    environment:
     - HUGO_ENV=production
    networks:
      - internal-network
    volumes:
      - ./src:/src
      - web-build-volume:/dest
    restart: unless-stopped

  nginx:
    container_name: nginx
    image: nginx:alpine
    mem_limit: 512m
    cpu_count: "4"
    labels:
      - are.containers.cool=true
    ports:
      - 8080:8080
    depends_on:
      - hugo
    networks:
      - web
      - internal-network
    volumes:
      - web-build-volume:/usr/share/nginx/html:ro
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
      - ./site.conf:/etc/nginx/conf.d/default.conf:ro
    restart: unless-stopped

Networks 2

Networks can be defined through Compose files


networks:
  web-network:
    name: web-network
    external: true
  internal-network:
    name: internal-network
    driver: bridge

Volumes 3

Persistent folders that can be used across services

volumes:
  web-build-volume:

Secrets 4

Secrets are data placed into the running container

secrets:
  cool_flag:
    file: ./flag.txt

Copies flag.txt to /run/secrets/cool_flag within the container.


Running Compose

docker composePurpose
upCreates the containers, pulls or builds missing images
downTears down the containers, networks
logsPrints STDOUT/STDERR from the container
pullDownloads/Updates images, but doesn’t start containers
topLists internel container processes
exec (…)Run command within container

Compose Flags

docker composePurpose
-f (PATH)Use (PATH) as the compose.yml
up -dDetach container, non-interactive
up –no-recreateUses existing containers
logs -fFollows logs

What commands do I use most often?

docker compose pull
docker compose down
docker compose up --no-recreate -d

Container Management Tools

NamePurpose
lazydockerLook through containers, their logs, volumes, etc.
ctopTUI for basic container managment.
diveLooking through container layers.

Notes

Docker used to not come with compose. Instead using a package named docker-compose.

Podman Compose works as a drop-in replacment of Docker Compose