docker 命令补全
补全:
安装docker自带包:
source /usr/share/bash-completion/completions/docker
缺少下面的包,TAB会报错
yum install -y bash-completion
sh /usr/share/bash-completion/bash_completion
进入docker:
安装工具:
yum -y install util-linux
查看docker的Pid:
docker inspect -f "{{ .State.Pid }}" mydocker
借助工具进入docker,退出时docker进程不退出
nsenter -t 7008 -m -i -u -n -p
简单命令脚本:
vim docker_in.sh
#!/bin/bash in_docker(){ container=$1 container_pid=$(docker inspect -f "{{ .State.Pid }}" $container) nsenter -t $container_pid -m -i -u -n -p } in_docker $1
执行:sh docker_in.sh mydocker
同效命令:
docker exec -it mydocker /bin/bash