Skip to content

Instantly share code, notes, and snippets.

@gcommit
Last active July 27, 2023 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gcommit/7594f793b871c819084c7e629031cf9c to your computer and use it in GitHub Desktop.
Save gcommit/7594f793b871c819084c7e629031cf9c to your computer and use it in GitHub Desktop.
#!/bin/bash
app=$1
if [ "$#" -ne 1 ]; then
echo "./docker_network.sh [app_id]"
else
case "$1" in
help)
echo "./docker_network.sh [app_id]"
;;
*)
if [ -f /tmp/inspect.txt ]; then
rm /tmp/inspect.txt
echo "inspect.txt found! Will remove now"
fi
if [ -f /tmp/inspect2.txt ]; then
rm /tmp/inspect2.txt
echo "inspect2.txt found! Will remove now"
fi
docker network inspect $app | grep Name > /tmp/inspect.txt
sed -i '1d' /tmp/inspect.txt
cut -d' ' -f18- /tmp/inspect.txt > /tmp/inspect2.txt
sed -i 's/^.//' /tmp/inspect2.txt
sed -i 's/.\{2\}$//' /tmp/inspect2.txt
clients_array=( $(cat /tmp/inspect2.txt) )
for i in "${clients_array[@]}"; do
docker network disconnect -f $app $i
echo "Disconnected $i from $app"
done
echo "Finished [SUCCESS] !"
;;
esac
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment