Detach network from docker containers

You might need to remove a docker network and recreate it when playing around with network configurations. If you have multiple containers connected to a network, you can use the following command to detach all containers from a network. In the following example I am detaching all containers from the reverse_proxy network:

 sudo docker network inspect -f '{{range .Containers}}{{.Name}} {{end}}' reverse_proxy | xargs -r -n1 sh -c 'sudo docker network disconnect reverse_proxy "$0" && echo "Disconnected $0"'