编写一个脚本用户进入容器

编写一个脚本用户进入容器

[root@linux-node1 ~]# vim docker_in.sh
#!/bin/bash
# Use nsenter to access docker
docker_in(){
NAME_ID=$1
PID=$(docker inspect --format "{{ .State.Pid }}" $NAME_ID)
nsenter --target $PID --mount --uts --ipc --net --pid
}
docker_in $1

[root@linux-node1 ~]# chmod +x docker_in.sh

[root@linux-node1 ~]# ./docker_in.sh mydocker

[root@94bb1c151fbc /]# exit
logout

[root@linux-node1 ~]#

猜你喜欢

转载自www.cnblogs.com/zhouwanchun/p/12559413.html