Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: August 19, 2025
Docker has revolutionized how developers build, share, and run containerized applications. Yet even as it streamlines workflows, users occasionally encounter cryptic errors. Regularly, it involves understanding how Docker’s components interact, particularly when cleaning up after use. When running the rm command, one of the most common errors is “Network has active endpoints“.
Despite intentions to tidy up, Docker prevents the removal because the network still has “active endpoints.” In this tutorial, we dig into what Docker networking entails, what endpoints are, why they linger, and the steps we must take to resolve this commonly encountered error. We’ll cover not only the commands but the rationale behind them, with real-world examples and best practices.
In Docker terminology, an endpoint is the connection point between a container and a network. Closely, we think of it like a virtual cable plugging a container into the virtual switch. Let’s see how to run an endpoint and assign it a name and network in a single prompt:
# docker run -d --name my_app1 --network my_bridge_net nginx
Next, let’s break down the steps that follow this command in the background:
Behind the scenes, Docker uses a bridge network driver by default for standalone containers. This driver creates an isolated subnet that allows containers to communicate. Let’s create a custom network:
# docker network create my_bridge_net
Docker sets up a virtual switch, assigns a subnet, and enables containers attached to this network to communicate using virtual Ethernet interfaces inside the containers. The moment a container joins this network, it creates an endpoint by plugging into this virtual topology.
In addition, it’s important to understand the lifecycle of the endpoint, its creation, and its termination.
Endpoints are created when containers are attached to networks. Notably, they persist until one of two conditions is met:
Furthermore, stopping a container (docker stop) does not remove the endpoint. Consequently, that lingering endpoint often causes the “network has active endpoints” issue.
However, the question remains: Why do Endpoints Impact Network Removal? The answer to this is that Docker prohibits deleting a network with active endpoints. This safeguard prevents disrupting live connections or network assignments, which could cause data loss or instability. Hence, attempting to remove such a network fails with the error “network has active endpoints “.
Now, we’ll move forward with identifying the root cause of this common error. Let’s use the rm command to remove my_bridge_net:
# docker network rm my_bridge_net
Error response from daemon: error while removing network: network my_bridge_net id <hash>: network has active endpoints
In this section, the aim is to help parse the error, understand the culprits, and help diagnose the problem to find the root cause quickly.
First, let’s attempt to remove an instance my_bridge_net using the rm command:
# docker network rm my_bridge_net
Next, let’s parse the error:
Error response from daemon:
error while removing network: network <network-name> id <hash>: network has active endpoints
Docker identifies one or more containers still connected via endpoints—even if they no longer run. Hence, this is why it is mandatory to understand the common causes:
Understanding this makes the error message clearer and highlights a better signal of what needs attention.
To identify the culprit, we need to inspect the network to determine what’s attached by using the network inspect command:
# docker network inspect \
--format '{{range $cid,$v := .Containers}}{{printf "%s: %s\n" $cid $v.Name}}{{end}}' \
my_bridge_net
e5f1a3c84b3b: my_app1
9d8c7b6a5f4e: my_app2
From the output, we can detect a key insight: There are containers still linked to our network, namely my_app1 and my_app2. Finally, we have the targets for resolution.
In this section, we’ll go over different methods to resolve this issue.
The first method we’ll cover is to stop and remove all containers:
# docker container stop my_app1 my_app2
# docker container rm my_app1 my_app2
After stopping and removing the containers, we attempt again to remove the network my_bridge_net:
# docker network rm my_bridge_net
This is the most thorough fix. We guarantee success when we can remove the containers.
In case we want to preserve a container’s state, instead of stopping it and removing it, we can disconnect it from the network:
# docker network disconnect -f my_bridge_net my_app1
# docker network disconnect -f my_bridge_net my_app2
# docker network rm my_bridge_net
The forced disconnect removes the endpoint cleanly.
On rare occasions, when all else fails, an endpoint may persist even after container removal; that is, a ghost endpoint. In this case, we restart Docker as this might be the quickest and most useful method to use, as it resets its internal state:
# On Linux systems
$ sudo systemctl restart docker
# Verify daemon is back online
$ docker info
# Retry network removal
$ docker network rm my_bridge_net
This sequence of actions involves restarting the Docker service on a Linux system, followed by verifying its operational status. Once confirmed, the final step is to remove a specified Docker network. Essentially, it’s a troubleshooting measure to ensure Docker is functioning correctly before attempting to delete a network that might have been causing issues.
This section observes how we might apply the above strategies in real production use cases.
In other situations, if our system administrator uses the Docker compose command, this may result in unidentified problems.
When using Docker Compose, it often creates a default network named <project>_default. We’ll often remove this infrastructure with docker-compose down:
# docker compose down
However, even after running the command above, Compose can sometimes leave behind network endpoints.
To address this, we can add the remove-orphans option:
# docker compose down --remove-orphans
# docker network rm <project>_default
This ensures that all containers—both named and orphaned—are removed, and no stray endpoints remain.
Interestingly, Compose relies on user-defined bridge networks similar to the default bridge driver. These behave like isolated virtual switches, and Docker wires containers through endpoints just like in manual setups. Nevertheless, we use compose down in a situation where the network is defined externally from the compose file.
We shouldn’t always use –remove-orphans when removing network endpoints in containers because it can unintentionally remove containers from other projects that share the same network but aren’t defined in the current Compose file.
Finally, if we often use Jenkins, we might run into Jenkins pipeline network Cleanup issues.
Let’s imagine a Jenkins script that takes down its CI infrastructure in the following way:
# docker compose down
# docker network rm my_bridge_net
If our script gets the “network has active endpoints” error, we can apply what we’ve learned already to remove orphans. That is, we can add the –remove-orphans flag:
# docker compose down --remove-orphans
# docker network rm my_bridge_net
Though note that if this is happening consistently, we may want to investigate first using our other diagnostic measures.
To resolve the issue, we update the pipeline script to inspect the network and automatically remove any lingering endpoints before attempting to delete the network. Accordingly, this makes the cleanup process deterministic and reliable.
In some CI/CD setups, Docker Compose can mistakenly manage shared or pre-existing networks, leading to unexpected conflicts during orchestration. Hence, a simple fix is to define the network as external in our docker-compose.yml:
networks:
my_bridge_net:
external: true
This tells Compose to use the existing network without trying to create or delete it, thus preventing accidental reuse or destruction.
If multiple pipeline runs share a static network name, collisions and race conditions can occur, especially in parallel executions. Accordingly, the best practice would be to use dynamic naming for networks:
# network_name: myapp_${GIT_COMMIT}
Here, we inject a unique identifier (like the Git commit hash) into the network name, avoiding overlap between concurrent jobs and eliminating the need for manual cleanup.
In this article, we addressed the common Docker error: “network has active endpoints.” This error occurs when we try to remove a Docker network that still has connected containers. In addition, we explained the fundamentals of Docker networking and what endpoints are. From there, we showed how to identify the containers causing the issue.
To fix it, we covered how to stop and remove containers, disconnect them forcefully, or restart the Docker daemon. Finally, we also provided practical advice for managing Docker Compose networks and CI pipelines.