进入容器 docker_login.sh
#!/bin/bash name=$1 basedir=`cd $(dirname $0); pwd -P`/$0 if [ $# -eq 1 ];then docker exec -it $name /bin/bash else echo "Usage: $basedir {CONTAINER ID | CONTAINER NAMES}" && exit 2 fi
使用 nsenter进入容器
#!/bin/bash
# Use nsenter to access docker
basedir=`cd $(dirname $0); pwd -P`/$0
if [ $# -ne 1 ];then
echo "Usage: $basedir {CONTAINER ID | CONTAINER NAMES}" && exit 2
fi
docker_in(){
NAME_ID=$1
PID=$(docker inspect -f "{{ .State.Pid }}" $NAME_ID)
nsenter -t $PID -m -u -i -n -p
}
docker_in $1