如何使用nsenter 进入Docker容器


安装nsenter

docker run -v /usr/local/bin:/target jpetazzo/nsenter

solumuser@ubuntu14044:~/devstack$ docker run -v /usr/local/bin:/target jpetazzo/nsenter
Unable to find image 'jpetazzo/nsenter:latest' locally
latest: Pulling from jpetazzo/nsenter
0e0f419fdc20: Pull complete 
91a0e4c51245: Pull complete 
661a5335f074: Pull complete 
0e11d298ab23: Pull complete 
06fbbd71fa48: Pull complete 
188740f5f5e6: Pull complete 
a2973bb5c627: Pull complete 
f11e19d48f83: Pull complete 
bff1c547022e: Pull complete 
51a6e49096e7: Pull complete 
311ff5fb25c1: Pull complete 
2fe219367210: Pull complete 
e7b0665269ca: Pull complete 
307e5c0ca25c: Pull complete 
6033a7753dc8: Pull complete 
e28b87694a35: Pull complete 
e3eb825e4e57: Pull complete 
4767c77d2871: Pull complete 
a2bd5169402e: Pull complete 
3b642f673420: Pull complete 
Digest: sha256:8c35f1452bc02dc3432862b869a2f35cf6384c6e28c28ede0f5c76f9891e2e9b
Status: Downloaded newer image for jpetazzo/nsenter:latest
Installing nsenter to /target
Installing docker-enter to /target
Installing importenv to /target

先计算容器的PID

PID=$(docker inspect --format {{.State.Pid}} )

solumuser@ubuntu14044:~/devstack$ docker ps
CONTAINER ID        IMAGE                                                                                                         COMMAND                CREATED             STATUS              PORTS               NAMES
e6551c6bf7e7        98b7ac1054f74e97840618198d699cec-java_app-20160517t175809236072150-1713a757d34ca340211473f322e0fc2406d3f65d   "/bin/bash -c 'sourc   16 hours ago        Up 16 hours                             nova-148a593f-d75c-4ac8-8cad-95c2ee7ffefd   
solumuser@ubuntu14044:~/devstack$ PID=$(docker inspect --format {{.State.Pid}} nova-148a593f-d75c-4ac8-8cad-95c2ee7ffefd )

进入容器

nsenter --target $PID --mount --uts --ipc --net --pid

solumuser@ubuntu14044:~/devstack$ sudo nsenter --target $PID --mount --uts --ipc --net --pid
root@instance-0000000e:/# pwd
/
root@instance-0000000e:/# ls
app  bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  solum  srv  sys  tmp  usr  var

你可能感兴趣的:(docker)