nsenter命令

用途

容器一般为精简镜像,缺乏相关指令和工具,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。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 作用: 进入其他linux命名空间执行操作。如从主机进入容器的命名空间,或者从容器进入主机的命名空间。一般情况下,...
    wangfeiq阅读 1,077评论 0 1
  • Docker — 云时代的程序分发方式 要说最近一年云计算业界有什么大事件?Google Compute Engi...
    ahohoho阅读 15,661评论 15 147
  • nsenter命令的语法: 示例: 运行一个nginx容器,查看该容器的pid: 在Kubernetes中,在得到...
    rushui阅读 1,982评论 0 0
  • 一.docker 是什么: 2.安装docker 系统:ubuntu16.04 使用脚本自动安装 Docker 官...
    Black_Sun阅读 2,162评论 0 2
  • docker容器 1:什么是容器? 容器就是在隔离的环境运行的一个进程,如果进程停止,容器就会销毁。 隔离的环境拥...
    Zh_bd92阅读 301评论 0 0