0Pricing
Go Academy · Lesson

Docker Compose for Local Development

Linking Go service with PostgreSQL and Redis

Docker Compose for Local Development is a free Go Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Go Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why Docker Compose?

Docker Compose orchestrates multiple containers (app, database, cache, message broker) for local development, reproducing a production-like environment without manual service setup.

docker-compose.yml structure

Define services, networks, and volumes in a YAML file:

services:
  app:
    build: .
    ports: ["8080:8080"]
    environment:
      - DATABASE_URL=postgres://app:pass@db/mydb
    depends_on: [db]
  db:
    image: postgres:15
    environment:
      POSTGRES_USER: app
      POSTGRES_PASSWORD: pass
      POSTGRES_DB: mydb
    volumes:
      - pgdata:/var/lib/postgresql/data
volumes:
  pgdata:

Live reload with Air

Use github.com/air-verse/air for live reloading during development. Mount the source into the container and run air instead of the binary:

app:
  volumes:
    - .:/app
  command: air

Health checks

Define health checks so depends_on waits for the DB to be truly ready, not just started:

db:
  healthcheck:
    test: ["CMD-SHELL", "pg_isready -U app"]
    interval: 5s
    timeout: 3s
    retries: 5
app:
  depends_on:
    db:
      condition: service_healthy

Overrides for environment

Use docker-compose.override.yml (automatically merged) for local-only settings, keeping the base file clean for CI:

# docker-compose.override.yml
services:
  app:
    volumes: [".:/app"]  # source mount for live reload

Named networks

Place services on a shared custom network for DNS-based service discovery by service name:

networks:
  backend:
    driver: bridge
services:
  app:
    networks: [backend]
  db:
    networks: [backend]

Environment files

Use the env_file key to load .env files into the container, keeping secrets out of the YAML:

app:
  env_file: .env.local

Running commands

Common Compose commands:

docker compose up -d      # start in background
docker compose down -v    # stop and remove volumes
docker compose logs -f app # stream app logs
docker compose exec db psql -U app mydb # run in container

Seeding the database

Mount SQL seed files into the postgres image's /docker-entrypoint-initdb.d directory — they run on first container creation:

db:
  volumes:
    - ./migrations:/docker-entrypoint-initdb.d

Profiles

Use Compose profiles to start optional services (e.g., a monitoring stack) only when needed:

services:
  grafana:
    profiles: ["monitoring"]

Compose in CI

Run integration tests against real services in CI with Compose. GitHub Actions supports Docker Compose natively; use health checks to wait for services to be ready.

Quick Check

How do you ensure the app container waits for the database to be ready in Docker Compose?

Recap: Docker Compose

Key points:

  • docker-compose.yml defines all services, networks, volumes
  • depends_on + healthcheck for service readiness
  • Override files for local dev settings; env_file for secrets
  • Air for live reload; mount source as a volume

Frequently asked questions

Is the “Docker Compose for Local Development” lesson free?

Yes — the full text of “Docker Compose for Local Development” is free to read here on the web, and the Go Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Go Academy course, upgrade to CoddyKit PRO.

What will I learn in “Docker Compose for Local Development”?

Linking Go service with PostgreSQL and Redis You practise Go Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Go Academy?

No prior experience is required. Go Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Docker Compose for Local Development” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Go Academy lesson?

Yes. Every Go Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Multi-Stage Docker Builds for Go
  2. Environment Config and Secrets
  3. Docker Compose for Local Development
  4. Health Checks and Production Tuning
← Back to Go Academy