compose.yaml file that sets up PostgreSQL for local development and can be adapted for production use.
Docker Compose setup
The includedcompose.yaml file provides a PostgreSQL database service:
Environment setup
Create environment file
Create a
.env file in the root directory with the following variables:Generate a secure random secret for
BETTER_AUTH_SECRET using:Start PostgreSQL
Launch the database container:This starts PostgreSQL in the background with persistent storage.
Run database migrations
Apply Prisma migrations to set up the database schema:Or from the
apps/web directory:Build the application
Build the Next.js application for production:This command:
- Generates the Prisma client
- Deploys migrations
- Builds the Next.js app
Adding a web service
To containerize the Toots application itself, extend thecompose.yaml file:
You’ll need to create a
Dockerfile in the project root. See the production deployment guide for Dockerfile recommendations.Useful commands
| Command | Description |
|---|---|
docker compose up -d | Start services in background |
docker compose down | Stop and remove containers |
docker compose logs -f | View container logs |
docker compose ps | List running services |
docker compose restart | Restart all services |
pnpm --filter web db:studio | Open Prisma Studio |
Troubleshooting
Connection refused errors
If you see “connection refused” errors when connecting to the database:- Verify PostgreSQL is running:
docker compose ps - Check the
DATABASE_URLmatches your Compose configuration - Ensure the database port (5432) isn’t already in use
Migration failures
If migrations fail:- Verify the database is accessible
- Check database credentials in
.env - Try resetting the database (⚠️ this will delete all data):