-
-
Save jarek-przygodzki/e306dd48a00d42e244f1f1f8f4281153 to your computer and use it in GitHub Desktop.
Create symlinks for network namespaces inside docker containers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This simple script creates symlinks for network namespaces of docker containers, | |
# then you can interact to that network namespace with built-in iproute2 on linux. | |
# See iproute2 convention in: http://man7.org/linux/man-pages/man8/ip-netns.8.html | |
container_ids=`docker ps -aq` | |
for cid in $container_ids | |
do | |
pid=`docker inspect -f '{{.State.Pid}}' $cid` | |
if [ ! -f "/var/run/netns/$cid" ]; then | |
ln -s /proc/$pid/ns/net /var/run/netns/$cid | |
fi | |
echo "=================== Check network namespaces ===============" | |
ip netns exec $cid ip addr show eth0 | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
container_ids=`docker ps -aq` | |
for cid in $container_ids | |
do | |
pid=`docker inspect -f '{{.State.Pid}}' $cid` | |
if [ -f "/var/run/netns/$cid" ]; then | |
rm /var/run/netns/$cid | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment