san3Xian / randomMark

用github repo做一些随记好了,内容在issues里。github page中仅为试验田🧪
https://qc47.net
4 stars 0 forks source link

docker container net namespace debug script #19

Open san3Xian opened 4 years ago

san3Xian commented 4 years ago

give this script execute permission and add it to your PATH variable

#!/bin/bash

############################################
#
#  Author: WILO
#  Todo: syntax check
#        list docker containers and select
#
############################################

set -ex
pid=`docker inspect $1 | grep "Pid\"" | grep -oP "(\d)*" `
mkdir -p /var/run/netns
ln -sf /proc/$pid/ns/net /var/run/netns/$1
ip netns exec  $@
rm /var/run/netns/$1