Remove multiple networks by name and ID
In this step, you will learn how to remove multiple Docker networks using a single command, specifying them by both name and ID. This is an efficient way to clean up several networks at once.
You can remove multiple networks by listing their names or IDs after the docker network rm
command, separated by spaces.
First, let's list the networks to get their IDs.
docker network ls
You should see network1
and network2
from the previous step. Note down the Network ID for network2
.
Now, let's remove network1
by its name and network2
by its ID in a single command. Replace <network2_id>
with the actual ID you noted down.
docker network rm network1 <network2_id>
If the networks are successfully removed, Docker will output the IDs of the networks that were removed.
You can verify that both networks have been removed by listing the available networks again using docker network ls
.
docker network ls
Neither network1
nor network2
should appear in the list.