我有一个 docker 容器,但我不想用来docker exec
在这个容器中启动其他进程(这与 docker 守护进程在管道数百 GB 数据时无法正常工作有关)。所以相反,我更喜欢只使用nsenter
进入容器或启动命令。
具体来说:
nsenter -n -m -u -i -p -t `docker inspect -f '{{.State.Pid}}' $1`
这工作正常,除了我创建的进程不能被容器本身杀死 - 即使进程是 root,我也得到一个权限被拒绝。
要重现这一点:
# start the container
docker run -dti --name test-container fedora:latest
# the following command prints the (low-numbered pid) of the sleep process, next to its own job, eg '6'
nsenter -n -m -u -i -p -t `docker inspect -f '{{.State.Pid}}' test-container` /bin/bash -c 'echo $$ ; exec sleep 9999' &
# try to kill the sleep from the container itself, eg if it was '6'
docker exec test-container kill 6
# reports: Permission denied
# killing it from the host works
它可能记录在联机帮助页的某个地方,但我无法弄清楚究竟是什么阻止了容器能够终止进程本身。