进入Docker容器的shell脚本 

 

使用root用户安装util-linux

yum -y install util-linux

 

编写脚本

vi docker-enter.sh 

 

#!/bin/bash

CNAME=$1

CPID=$(docker inspect --format "{{.State.Pid}}" $CNAME)

if [ "$#" -gt 1 ]; then

    nsenter --target $CPID --mount --uts --ipc --net --pid -- "$2"

else

    nsenter --target $CPID --mount --uts --ipc --net --pid -- /bin/bash

fi

 

 

使用:

./docker-enter.sh 容器名称

或者

 ./docker-enter.sh 容器名称 启动脚本( /bin/bash)

 

nsenter 可以访问另一个进程的名字空间。nsenter 要正常工作需要有 root 权限

 

参考:

https://github.com/jpetazzo/nsenter/issues/5

http://c.biancheng.net/cpp/view/2739.html

GitHub 加速计划 / li / linux-dash
13
2
下载
A beautiful web dashboard for Linux
最近提交(Master分支:4 个月前 )
186a802e added ecosystem file for PM2 5 年前
5def40a3 Add host customization support for the NodeJS version 5 年前
Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐