[root@yuanxiaolong tmp]# ls util-linux-2.24.tar.gz [root@yuanxiaolong tmp]# tar -zxf util-linux-2.24.tar.gz [root@yuanxiaolong tmp]# ls util-linux-2.24 util-linux-2.24.tar.gz [root@yuanxiaolong tmp]# cd util-linux-2.24
## 如果没有C编译器会报错如下: ## checking for gcc... no ## checking for cc... no ## checking for cl.exe... no ## configure: error: in `/root/app/tmp/util-linux-2.24': ## configure: error: no acceptable C compiler found in $PATH ## See `config.log' for more details
[root@yuanxiaolong util-linux-2.24]# cd .. [root@yuanxiaolong tmp]# vi docker-enter
#!/bin/sh
if [ -e $(dirname "$0")/nsenter ]; then # with boot2docker, nsenter is not in the PATH but it is in the same folder NSENTER=$(dirname "$0")/nsenter else NSENTER=nsenter fi
if [ -z "$1" ]; then echo"Usage: `basename "$0"` CONTAINER [COMMAND [ARG]...]" echo"" echo"Enters the Docker CONTAINER and executes the specified COMMAND." echo"If COMMAND is not specified, runs an interactive shell in CONTAINER." else PID=$(docker inspect --format "{{.State.Pid}}""$1") if [ -z "$PID" ]; then exit1 fi shift
if [ -z "$1" ]; then # No command given. # Use su to clear all host environment variables except for TERM, # initialize the environment variables HOME, SHELL, USER, LOGNAME, PATH, # and start a login shell. "$NSENTER"$OPTS su - root else # Use env to clear all host environment variables. "$NSENTER"$OPTS env --ignore-environment -- "$@" fi fi
[root@yuanxiaolong tmp]# chmod +x docker-enter
Step 6.查看正在运行的容器,然后利用脚本进入
1 2 3 4 5 6 7 8
[root@yuanxiaolong ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 64e466932bdd yuanxiaolong/centos-node-hello:latest node /src/index.js 3 hours ago Up 3 hours 8088/tcp prickly_shockley 496861d3a50d yuanxiaolong/centos-node-hello:latest node /src/index.js 3 hours ago Up 3 hours 8088/tcp backstabbing_nobel f7007b2bb4cb jwilder/nginx-proxy:latest forego start -r 3 hours ago Up 3 hours 0.0.0.0:80->80/tcp determined_nobel
[root@yuanxiaolong tmp]# sh docker-enter f7007b2bb4cb root@f7007b2bb4cb:~#