DebNet/script/expose-netns.sh

25 lines
525 B
Bash

#!/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