Docker Setup Overview
The project includes:- Multi-stage Dockerfile with dev, builder, and production targets
- Docker Compose configuration with hot reload support
- PostgreSQL service with health checks
- Development mode with full Go toolchain
Dockerfile Stages
TheDockerfile uses a multi-stage build with three targets:
Dev Stage
Based ongolang:1.26, includes the full Go toolchain for development:
Builder Stage
Compiles the binary with optimizations:Production Stage
Minimal Alpine-based image for deployment:Docker Compose Configuration
Thecompose.yaml defines two services:
App Service
- Builds using the
devtarget - Loads environment variables from
.env - Supports hot reload via Docker Compose watch
- Ignores
.git/and.llm/directories during sync
PostgreSQL Service
- Uses the
postgresprofile (opt-in) - Runs PostgreSQL 18 on Alpine Linux
- Exposes port 5432 to the host
- Includes health checks for container orchestration
Running with Docker
Start Full Stack
Start both the application and PostgreSQL:Start all services
docker compose --profile postgres up -d which:- Builds the app container (dev stage)
- Starts PostgreSQL with the postgres profile
- Runs both services in detached mode
Hot Reload with Docker Compose Watch
For active development with automatic rebuilds:- Monitors your source code for changes
- Automatically rebuilds the container on file changes
- Restarts the application with your updates
- Ignores
.git/and.llm/directories
The watch action is
rebuild, which means the container is rebuilt on changes. For faster iteration, consider running the app locally with make dev instead.Stop Services
Stop and remove all containers:Docker Commands Reference
| Command | Description |
|---|---|
make up | Start full stack (app + postgres) |
make down | Stop all services |
make watch | Hot reload via docker compose watch |
Database-Only Mode
If you prefer to run the application locally but use Docker for PostgreSQL:Run the app locally
localhost:5432 using the DATABASE_URL from your .env file.Building for Production
Build the production image:- Is based on Alpine Linux (~10MB base)
- Contains only the compiled binary and essential certificates
- Has no development tools or source code
- Uses
CGO_ENABLED=0for static linking
Troubleshooting
Container won’t start
Check logs for errors:Database connection issues
Verify PostgreSQL is healthy:DATABASE_URL in .env matches the container configuration.
Hot reload not working
Ensure you’re using Docker Compose with watch support (v2.22+):Next Steps
Database Setup
Learn about migrations and sqlc
Testing
Run tests in Docker
