{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreihcfocpqgx2hew4sz62gex47urt6sp4q7oevb7fqsyuninyj44qlm",
    "uri": "at://did:plc:25rdn5elo5izoxrmtis34zuk/app.bsky.feed.post/3mooje5a3aoj2"
  },
  "coverImage": {
    "$type": "blob",
    "ref": {
      "$link": "bafkreianpnzshdf6gi4ojyfpjubaksrgpue35btrtpu7xl6sdlqkooejuu"
    },
    "mimeType": "image/webp",
    "size": 19660
  },
  "path": "/zsevic/docker-compose-overview-32h9",
  "publishedAt": "2026-06-19T22:55:36.000Z",
  "site": "https://dev.to",
  "tags": [
    "docker",
    "dockercompose",
    "devops",
    "Docker Engine",
    "Postgres and Redis post",
    "Postgres and Redis containers with Docker Compose",
    "RabbitMQ container with Docker Compose",
    "MongoDB containers with Docker Compose",
    "Kafka containers with Docker Compose",
    "DynamoDB and SQS containers with Docker Compose",
    "code demos"
  ],
  "textContent": "Docker Compose runs multi-container applications from a single YAML file. One command can start an API, a database, a message broker, and supporting tools for local development - without installing each service on the host machine.\n\nThis post covers Compose concepts and commands. For ready-made stacks, see the service-specific posts linked at the end (Postgres/Redis, RabbitMQ, MongoDB, Kafka, DynamoDB/SQS).\n\n###  Prerequisites\n\n  * Docker Engine installed\n  * Compose V2 - use `docker compose` (with a space). Current Docker Desktop includes it; no separate Compose install is required.\n\n\n\n###  Mental model\n\n  * **Project** - the folder that contains `docker-compose.yml`. The project name defaults to the directory name and prefixes container names.\n  * **Services** - named containers defined in the file (`api`, `redis`, `postgres`). Each service maps to one image or build context.\n  * **Network** - Compose creates a default network so services resolve each other by name. From the `api` container, Redis is reachable at `redis:6379`, not `localhost:6379`.\n  * **Volumes** - named or bind mounts for data that survives `docker compose down` (unless you pass `-v`).\n\n\n\n###  Minimal compose file\n\nA two-service stack: a Node API and Redis. No top-level `version:` key - it is deprecated in the current Compose specification.\n\n\n\n    services:\n      api:\n        build: .\n        ports:\n          - 3000:3000\n        environment:\n          REDIS_URL: redis://redis:6379\n        depends_on:\n          - redis\n\n      redis:\n        image: redis:alpine\n        volumes:\n          - redis-data:/data\n\n    volumes:\n      redis-data:\n\n\nRun `docker compose up --build` from the directory that contains this file.\n\n###  Core concepts\n\n**Ports** - map host ports to container ports as `host:container`:\n\n\n\n    ports:\n      - 3000:3000\n\n\n**Environment** - inline variables or an env file:\n\n\n\n    environment:\n      REDIS_URL: redis://redis:6379\n\n    env_file:\n      - .env\n\n\n**Volumes** - **named volumes** are managed by Docker (good for database data). **Bind mounts** map a host path into the container (good for live code reload during development):\n\n\n\n    volumes:\n      - redis-data:/data        # named\n      - ./src:/app/src:ro       # bind mount\n\n\n**Networks** - services on the default network can reach each other by service name. Custom networks isolate groups of services (see the Postgres and Redis post for a multi-network example).\n\n**depends_on** - controls startup order. It does not wait for the dependency to be ready; add a `healthcheck` or retry logic in the app when you need readiness.\n\n**restart** - policies like `on-failure:3` or `unless-stopped` keep containers running after crashes or host reboots.\n\n**healthcheck** - optional probe so Compose and other services know when a container is ready:\n\n\n\n    healthcheck:\n      test: ['CMD', 'redis-cli', 'ping']\n      interval: 5s\n      timeout: 3s\n      retries: 5\n\n\n###  Commands\n\nCommand | Purpose\n---|---\n`docker compose up` | Start services (foreground, logs in terminal)\n`docker compose up -d` | Start in detached mode\n`docker compose up --build` | Rebuild images before starting\n`docker compose down` | Stop and remove containers\n`docker compose down -v` | Also remove named volumes\n`docker compose ps` | List running services\n`docker compose logs -f api` | Follow logs for one service\n`docker compose exec api sh` | Open a shell in a running container\n`docker compose pull` | Pull latest images\n\n###  When to use what\n\nTool | Best for\n---|---\n`docker run` | One-off containers, quick image tests\n**Docker Compose** | Local multi-service stacks, dev databases and queues\nKubernetes | Production orchestration, scaling, rolling deploys\n\n###  Service-specific setups\n\n  * Postgres and Redis containers with Docker Compose - databases with Pgweb and Redis Commander\n  * RabbitMQ container with Docker Compose - message broker with management UI\n  * MongoDB containers with Docker Compose - MongoDB with Mongo Express\n  * Kafka containers with Docker Compose - KRaft-mode Kafka with Kafka UI\n  * DynamoDB and SQS containers with Docker Compose - DynamoDB Local and ElasticMQ\n\n\n\n###  Demo\n\nRunnable files for this post live in the `docker-compose-overview-demo` folder. Get access via code demos.",
  "title": "Docker Compose overview"
}