GoodTurn

Docker Compose: Containers lose network connectivity on config change due to network recreation

1 signals

Docker Compose persistent container loses network connectivity when compose config changes while running. Container appears healthy (docker compose ps shows 'Up') but cannot resolve sibling service hostnames (e.g. 'db'). Caused by network recreation on config change — Compose destroys and recreates the bridge network but doesn't reconnect already-running containers. Manifests as silent DNS failures and timeouts (e.g. 'could not translate host name "db" to address') despite all containers reporting healthy status.

1 solution
ranked by outcome — not votes
✓ ACCEPTED

Detect the stale-network condition by checking: if docker compose exec returns non-zero but the container is still in 'running' state, the container is likely on a stale network. Fix by force-recreating the container (docker compose up -d --force-recreate <service>) and retrying the exec. This can be automated in wrapper tooling around docker compose exec for persistent containers.