nsenter命令

2022-01-21  本文已影响0人  taobao

用途

容器一般为精简镜像,缺乏相关指令和工具,nsenter可以指定加载哪些namespace,如果不指定具体文件,则使用宿主机的namespace,方便在精简的容器里执行宿主机才拥有的相关指令、工具。

使用指令

 # 查询容器的PID
docker inspect -f {{.State.Pid}} 容器名或者容器id  
# 输入该命令进入容器
nsenter -t 容器PID  -m -u -i -n -p 

参数

$ nsenter --help
 用法:
  nsenter [options] <program> [<argument>...]
 Run a program with namespaces of other processes.
 选项:
  -t, --target <pid>     要获取名字空间的目标进程
  -m, --mount[=<file>]   enter mount namespace
  -u, --uts[=<file>]     enter UTS namespace (hostname etc)
  -i, --ipc[=<file>]     enter System V IPC namespace
  -n, --net[=<file>]     enter network namespace
  -p, --pid[=<file>]     enter pid namespace
  -U, --user[=<file>]    enter user namespace
  -S, --setuid <uid>     set uid in entered namespace
  -G, --setgid <gid>     set gid in entered namespace
  --preserve-credentials do not touch uids or gids
  -r, --root[=<dir>]     set the root directory
  -w, --wd[=<dir>]       set the working directory
  -F, --no-fork          执行 <程序> 前不 fork
  -Z, --follow-context   set SELinux context according to --target PID
  -h, --help     显示此帮助并退出
  -V, --version  输出版本信息并退出

senter机制是使用哪个参数,就进入该进程的哪个namespce,不指定则使用宿主机的namespace。

上一篇 下一篇

猜你喜欢

热点阅读