docker debug

http://blog.csdn.net/jincm13/article/category/1196013

http://blog.youlingman.info/debugging-iptables-with-raw-table/ 

nmap -v sn 10.239.19.192/26 

查看 10.239.19.192/26网段没有使用的IP

udhcpc

# sudo docker run -it --net=host --privileged -v /var/run/:/var/run/ -v /etc:/etc -v /lib/modules:/lib/modules:ro fab9cc6c22f0

1. install nsenter

cd /tmp; curl https://www.kernel.org/pub/linux/utils/util-linux/v2.24/util-linux-2.24.tar.gz | tar -zxf-; cd util-linux-2.24;
./configure --without-ncurses
 make nsenter && sudo cp nsenter /usr/local/bin
docker ps
docker inspect --format '{{ .State.Pid }}' eeb1310d00dc
nsenter --target 45912 --mount --uts --ipc --net --pid
 
 2076  docker ps
 2077  docker ps -al
 2078  docker stop eeb1310d00dc
 2079  docker ps -al
 2080  docker rm eeb1310d00dc
 2081  docker ps -al
 2082  sudo docker run -d --net=host --privileged -v /var/run/netns/:/var/run/netns/ -v /etc:/etc -v /lib/modules:/lib/modules:ro fab9cc6c22f0
 2083  docker ps -al
 2084  docker top hungry_kowalevski
 2085  nsenter --target 45912 --mount --uts --ipc --net --pid
 2086  docker inspect --format '{{ .State.Pid }}' eeb1310d00dc
 2087  docker ps -a
 2088  docker inspect --format '{{ .State.Pid }}' 233389d9acf9
 2089  nsenter --target 57704 --mount --uts --ipc --net --pid
 2090  history |less

nsenter or nsinit 命令是一个可以在指定进程的命令空间下运行指定程序的命令。它位于util-linux包中。

当我们通过pod name进入指定进程时, 可以使用以下命令

cat nspod.sh

if [ -z "$1" ]; then
  echo "Get pod name from env value PODNAME"
else
  PODNAME=$1
fi

if [ -z "$PODNAME" ]; then
  echo "No pod name, you can get pod name by: "
  echo " kubectl get pod"
  exit 1
fi

DOCID=`kubectl get pod $PODNAME -o template --template='{{range .status.containerStatuses}}{{.containerID}}{{end}}' | cut -d "/" -f 3`
echo "Docker id of $PODNAME is: $DOCID"
DOCPID=`sudo docker inspect -f {{.State.Pid}} $DOCID`
echo "PID of $PODNAME is: $DOCPID"
sudo nsenter -n -t $DOCPID
原文地址:https://www.cnblogs.com/shaohef/p/4702784.html