Skip to content
Latchkey

GitLab CI "Failed to remove network for build" in CI

After a job the Docker executor tries to delete the temporary network it created and fails because a container is still attached or the network is in use. The job may still pass, but cleanup errors accumulate.

What this error means

The job log ends with "ERROR: Failed to remove network for build" or the runner logs "error while removing network: network ... has active endpoints".

GitLab Runner
ERROR: Failed to remove network for build                 error=networks.id=abcd... cannot be removed: network has active endpoints

Common causes

A leftover container holds the network

A service or build container did not exit cleanly, so the network still has active endpoints and cannot be removed.

Docker state pressure on the runner host

Accumulated dangling networks and containers on a busy host make cleanup flaky.

How to fix it

Prune leftover Docker state on the host

  1. On the runner host, remove dangling containers and networks.
  2. Schedule periodic pruning so state does not accumulate.
  3. Re-run the affected job.
Terminal
docker container prune -f
docker network prune -f

Reduce build container leaks

Ensure services stop cleanly and avoid detaching long-lived containers inside jobs that outlive the build network.

How to prevent it

  • Prune Docker networks/containers on runner hosts on a schedule.
  • Make sure job services exit cleanly at job end.
  • Monitor runner hosts for accumulating dangling networks.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →