I have docker network "my_network". I want to remove this docker network with docker network rm my_network
. Before it I should disconnect all my containers from this network. I can use docker network inspect
and get output like
[
{
"Name": "my_network",
"Id": "aaaaaa",
"Scope": "some_value",
"Driver": "another_value",
"EnableIPv6": bool_value,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "10.0.0.0/1"
}
]
},
"Internal": false,
"Containers": {
"bbb": {
"Name": "my_container_1",
"EndpointID": "ENDPOITID1",
"MacAddress": "MacAddress1",
"IPv4Address": "0.0.0.0/1",
"IPv6Address": ""
},
"ccc": {
"Name": "my_container_2",
"EndpointID": "ENDPOINTID2",
"MacAddress": "MacAddress2",
"IPv4Address": "0.0.0.0/2",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {}
}
]
It is okay to manual disconnect if I have only several containers but if I have 50 containers I have problem. How can I disconnect all containers from this network with single or several command?
docker network inspect
has a format option.That means you can list all Container names with:
That should then be easy, by script, to read each name and call
docker network disconnect
.wwerner proposes below in the comments the following command:
In multiple line for readability:
Adding: