Linux 使用 nsenter 进入 Docker 容器排查问题

Linux Docker About 684 words

安装 nsenter

make&make build方式,源码下载:

https://mirrors.edge.kernel.org/pub/linux/utils/util-linux

yum安装

yum install util-linux -y

查看容器 PID

docker inspect --format "{{ .State.Pid}}"  <container id>

进入容器命令

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

参数说明

--mount:进入到mount namespace--uts:进入到uts namespace--ipc:进入到System V IPC namaspace--net:进入到network namespace--pid:进入到pid namespace--user:进入到user namespace

-m 参数

加 m 参数

nsenter -t 容器PID -m -u -i -n -p

不加 m 参数

nsenter -t 容器PID -u -i -n -p

区别

-m:容器里没有ping等命令

不加-m:容器里有一些基础命令

原因

-m是进入mount namespace的,这个名称空间是用来文件系统名称空间,所以当我们不加-m的时候,使用的是宿主机的文件系统,可以使用宿主机内的命令对容器进行问题的排查。

参考

https://www.jianshu.com/p/3af03bd3af2e

Views: 1,199 · Posted: 2022-06-20

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh