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. This is lesson 3 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Go Academy learning path, and your progress syncs across the web and the CoddyKit app. The Go Academy course includes 4 lessons in total.
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: airHealth 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_healthyOverrides 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 reloadNamed 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.localRunning 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 containerSeeding 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.dProfiles
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
Learn Go with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 51
- Lessons
- 203
Frequently Asked Questions
Is the “Docker Compose for Local Development” lesson free?
Yes — any 3 lessons of the Go Academy learning path, including “Docker Compose for Local Development”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Go Academy course includes 4 lessons in total.
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, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 4.
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
- Multi-Stage Docker Builds for Go
- Environment Config and Secrets
- Docker Compose for Local Development
- Health Checks and Production Tuning