How to remove a network with active endpoints in Docker

Problem: ERROR: error while removing network

I wanted to run docker-compose down but it failed due to the following error:

ERROR

:

error

while

removing

network

:

network

<

your_network

>

id

cfcb4a603426f2cf71b1f971a9ecb0aae7e6c889a8dc4c55bfd1eb010d8a260b

has

active

endpoints

Solution

To solve this just run docker network inspect <your_network> with the rights permissions. (You may also use sudo if you have the permission).

The output of that command is something like this:

[

{

"Name"

:

"your_network"

,

"Id"

:

"cfcb4a603426f2cf71b1f971a9ecb0aae7e6c889a8dc4c55bfd1eb010d8a260b"

,

"Created"

:

"2021-05-05T10:58:08.216143067+02:00"

,

"Scope"

:

"local"

,

"Driver"

:

"bridge"

,

"EnableIPv6"

:

false,

"IPAM"

:

{

"Driver"

:

"default"

,

"Options"

:

null,

"Config"

:

[

{

"Subnet"

:

"10.0.38.0/24"

,

"Gateway"

:

"10.0.38.1"

}

]

}

,

"Internal"

:

false,

"Attachable"

:

true,

"Ingress"

:

false,

"ConfigFrom"

:

{

"Network"

:

""

}

,

"ConfigOnly"

:

false,

"Containers"

:

{

"cf8f158e34d07bb3be8ff73e21fc688dce1ba13a5b941a7a59aff1373a74be8f"

:

{

"Name"

:

"phpmyadmin_phpmyadmin_1"

,

"EndpointID"

:

"e77d58d75ee31a37ee2cced2658c36480c4f209d8eedf29d4d281f8073457eb1"

,

"MacAddress"

:

"02:42:0a:00:26:05"

,

"IPv4Address"

:

"10.0.38.5/24"

,

"IPv6Address"

:

""

}

}

,

"Options"

:

{}

,

"Labels"

:

{

"com.docker.compose.network"

:

"default"

,

"com.docker.compose.project"

:

"your_project"

,

"com.docker.compose.version"

:

"1.28.5"

}

}

]

In this case the network is your_network and the endpoint is in containers -> name.

Now you can use sudo docker network disconnect -f your_network phpmyadmin_phpmyadmin_1. This will disconnect the network from the instance, and you will be able to run docker-compose down without problems.

Source: This answer in Stack Overflow