Docker is an open-source containerization platform that allows you to quickly build, test, and deploy applications as portable containers that can run anywhere. In this quick tutorial, we will show you how to remove all unused networks in Docker. Also, how to remove one or more network by ID or by using a filter flag.
Removing Docker Networks
1./ Remove one or more networks
To remove one or more Docker networks use the docker network ls
command to find the ID of the networks you want to remove.
$ docker network ls NETWORK ID NAME DRIVER SCOPE 107b8ac977e3 bridge bridge local ab998267377d host host local h520032c3d31 jenkins-overlay bridge local 3bc81b63f740 none null local
Once you’ve located the networks you want to remove, use the the docker network rm
command followed by the NETWORK ID. For example to remove the network with the name jenkins-overlay run:
$ docker network rm h520032c3d31
If you get an error similar to the one shown below, it means that an existing container uses the network. To remove the network you will have to remove the container first.
Error response from daemon: network jenkins-overlay id 4g5293268bb91ad2498b38b0bca970083af87237784017be24ea208d2233c5aa has active endpoints
2./ Remove all unused network
Use the docker network prune
command to remove all unused networks.
$ docker network prune
You’ll be prompted to continue, use the -f
or --force
flag to bypass the prompt.
WARNING! This will remove all networks not used by at least one container. Are you sure you want to continue? [y/N]
3./ Remove networks using filters
With the docker network prune command you can remove networks based on condition using the filtering flag –-filter
. However, the currently supported filters are until
and label
. You can use more than one filter by using multiple --filter
flags.
For example, to remove all networks that are created more than 12 hours ago, run:
$ docker network prune -a --filter "until=12h"
Conclusion
You successfully learned how to remove all unused networks in Docker. Also, how to remove one or more network by ID or by using a filter flag.
What’s Next? You might want to check the following guides:
1 comment
Empty all my network of today