Skip to content

Commit cf787fd

Browse files
author
bigjohncodes
committed
Fix Docker networking race condition on first startup
- Add health check to Traefik proxy with ping endpoint - Make backend depend on proxy being healthy before starting - Ensures Docker networks are fully initialized before backend binds ports - Prevents connection timeout issues on first 'docker compose up' This fixes a race condition where the backend container would start and bind to port 8000 before Docker's network bridges were fully configured, causing connection timeouts from the host machine. The fix ensures the backend waits for the proxy (Traefik) to be healthy before starting, which guarantees all network routes and port forwarding rules are properly established.
1 parent fa87951 commit cf787fd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

compose.override.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ services:
1212
ports:
1313
- "80:80"
1414
- "8090:8080"
15+
healthcheck:
16+
test: ["CMD", "traefik", "healthcheck", "--ping"]
17+
interval: 5s
18+
timeout: 3s
19+
retries: 3
20+
start_period: 5s
1521
# Duplicate the command from compose.yml to add --api.insecure=true
1622
command:
1723
# Enable Docker in Traefik, so that it reads labels from Docker services
@@ -34,6 +40,8 @@ services:
3440
- --api
3541
# Enable the Dashboard and API in insecure mode for local development
3642
- --api.insecure=true
43+
# Enable ping endpoint for health checks
44+
- --ping=true
3745
labels:
3846
# Enable Traefik for this service, to make it available in the public network
3947
- traefik.enable=true
@@ -59,6 +67,9 @@ services:
5967
restart: "no"
6068
ports:
6169
- "8000:8000"
70+
depends_on:
71+
proxy:
72+
condition: service_healthy
6273
build:
6374
context: .
6475
dockerfile: backend/Dockerfile

0 commit comments

Comments
 (0)