Skip to content

Commit a09b4ac

Browse files
Update Docker images and add healthcheck (#69)
Summary for .devcontainer/docker-compose.yml: Added startup coordination so the app waits for Postgres to become healthy and Redis to start. Added a Postgres healthcheck using pg_isready to improve container readiness detection. Pinned Postgres from latest to postgres:17 for a more stable, reproducible dev environment. Pinned Redis to redis:7-alpine, which is a smaller, versioned image and can improve image pull time. Removed the obsolete top-level Compose version field to align with modern Docker Compose conventions. Kept the original network_mode: service:db behavior, so the app’s networking model is unchanged.
1 parent 7de6764 commit a09b4ac

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

‎.devcontainer/docker-compose.yml‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: "3"
2-
31
services:
42
app:
53
build:
@@ -9,27 +7,38 @@ services:
97
volumes:
108
- ..:/workspace:cached
119

12-
# Overrides default command so things don't shut down after the process ends.
10+
# Keep the development container running.
1311
command: sleep infinity
1412

15-
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
13+
# Start supporting services before the app container.
14+
depends_on:
15+
db:
16+
condition: service_healthy
17+
redis:
18+
condition: service_started
19+
1620
network_mode: service:db
1721

1822
db:
19-
image: postgres:latest
23+
image: postgres:17
2024
restart: unless-stopped
25+
2126
volumes:
2227
- postgres-data:/var/lib/postgresql/data
28+
2329
environment:
2430
POSTGRES_DB: app
2531
POSTGRES_USER: app_user
2632
POSTGRES_PASSWORD: app_password
2733

28-
# Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally.
29-
# (Adding the "ports" property to this file will not forward from a Codespace.)
34+
healthcheck:
35+
test: ["CMD-SHELL", "pg_isready -U app_user -d app"]
36+
interval: 5s
37+
timeout: 5s
38+
retries: 10
3039

3140
redis:
32-
image: redis
41+
image: redis:7-alpine
3342
restart: unless-stopped
3443

3544
volumes:

0 commit comments

Comments
 (0)