Skip to content

Commit f7d847b

Browse files
committed
New docker-compose file for multi-container setup (linked network, volume, and standalone postgres container).
1 parent fa6774c commit f7d847b

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

docker-compose.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Define the services (containers) that make up your application.
2+
services:
3+
# 1. The Next.js Web Application Service
4+
webapp:
5+
# Build the image from the Dockerfile in the current directory.
6+
build: .
7+
container_name: codebuilder-webapp
8+
# Ensure the webapp starts after the database is ready.
9+
depends_on:
10+
- db
11+
# Restart the container automatically unless it is explicitly stopped.
12+
restart: unless-stopped
13+
# Pass the .env file to the container for environment variables.
14+
env_file:
15+
- ./.env
16+
ports:
17+
# Map port 3000 on the host to port 3000 in the container.
18+
- "3000:3000"
19+
networks:
20+
# Connect this service to our custom network.
21+
- codebuilder-net
22+
23+
# 2. The PostgreSQL Database Service
24+
db:
25+
# Use the official PostgreSQL 15 image from Docker Hub.
26+
image: postgres:15-alpine
27+
container_name: codebuilder-postgres-db
28+
restart: unless-stopped
29+
# Pass the .env file, which must contain the DB credentials.
30+
env_file:
31+
- ./.env
32+
volumes:
33+
# Mount a named volume to persist the database data.
34+
# This is crucial to prevent data loss when the container is recreated.
35+
- postgres-data:/var/lib/postgresql/data
36+
networks:
37+
# Connect this service to our custom network.
38+
- codebuilder-net
39+
# Exposing the port is optional if only the webapp needs to connect,
40+
# but it's useful for debugging from your host machine.
41+
ports:
42+
- "5434:5432"
43+
44+
# Define the custom network that our services will share.
45+
# This allows them to communicate with each other using their service names
46+
# (e.g., the webapp can connect to 'db' on port 5432).
47+
networks:
48+
# This network will be named exactly 'codebuilder-net'
49+
# with no project prefix.
50+
codebuilder-net:
51+
name: codebuilder-net
52+
driver: bridge
53+
54+
# Define the named volumes for persistent data storage.
55+
# Docker manages the lifecycle of these volumes.
56+
volumes:
57+
postgres-data:

0 commit comments

Comments
 (0)