DebNet/script/expose-netns.sh

25 lines
525 B
Bash
Raw Normal View History

2024-10-23 07:09:50 +00:00
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: $0 <container id or name>"
exit 1
fi
echo "expose container $1 netns"
NETNS=`sudo docker inspect -f '{{.State.Pid}}' $1`
if [ ! -d /var/run/netns ]; then
sudo mkdir /var/run/netns
fi
if [ -f /var/run/netns/$NETNS ]; then
sudo rm -rf /var/run/netns/$NETNS
fi
sudo ln -s /proc/$NETNS/ns/net /var/run/netns/$NETNS
echo "done. netns: $NETNS"
echo "============================="
echo "current network namespaces: "
echo "============================="
ip netns