随着docker使用的深入,有一个痛点出现了,就是在用的docker容器启动命令是啥,

启动命令对应docker容器来说相当于容器的根,但是一般的使用场景,启动完容器之后,如果不刻意记录,启动命令就很容易丢失了

没有启动命令,就不敢轻易删除容器,还有容器内的数据是否挂在出来也不能及时发现,对后面的升级维护啥的造成困扰

docker官方也没有给出查看启动命令的工具,这个时候想拼凑出启动命令只能通过扒history或者docker inspect元数据慢慢分析了,费时费力

好在我们在一个开源的时代,还是有不少工具可以使用的

经过一番选型之后发现三个工具可供使用

1.runlike

优点:

显示启动命令格式工整,清晰易读

参数显示全

缺点:

启动命令参数过于冗余:不能准确还原启动命令

安装方式很不友好:需要通过pip安装,linux安装pip就是一个不小的坑,不过经过查找有docker版runlike 解决了这个问题

推荐指数:一般

相关资料:

pip安装官方指南:https://pip.pypa.io/en/stable/installation/

pip官方程序包下载:https://pypi.org/project/pip/#files

安装方式:https://www.cnblogs.com/happyflyingpig/p/16128887.html

安装方式2(pip3):https://blog.csdn.net/zfw_666666/article/details/128149274

dockerhub:https://hub.docker.com/r/assaflavie/runlike

安装python3:https://www.cnblogs.com/happyflyingpig/p/16367568.html

修改pip安装源:https://www.cnblogs.com/cjyp/p/9995261.html 

 

 

2.recod

优点:

参数显示比较全

缺点:

显示格式不够易读

推荐指数:一般

相关资料:

dockerhub:https://hub.docker.com/r/nexdrew/rekcod

 

3.get_command_4_run_container

优点:

基本能够准确还原出当时的启动命令

命令显示结构清晰易读

缺点:

暂无

推荐指数:非常推荐

dockerhub:https://hub.docker.com/r/cucker/get_command_4_run_container

使用方式:

可以将其封装为一个别名:

Usage:
# Command alias
docker pull cucker/get_command_4_run_container
echo "alias get_run_command='docker run --rm -v /var/run/docker.sock:/var/run/docker.sock cucker/get_command_4_run_container'" >> ~/.bashrc
source ~/.bashrc

如果要经常跑 docker image prune -af 命令清理废弃镜像文件,可以执行下

docker run cucker/get_command_4_run_container

留一个容器存档即可

 

 

 

这样就可以这样用了:get_run_command [容器名称]/[容器ID]

# Excute command
## For all runing containers
get_run_command {allrun}

## For all containers include shutdown
get_run_command {all}

## For one or more containers
get_run_command <CONTAINER> [CONTAINER...]

 

 

参考文档:

https://blog.51cto.com/u_10950710/6149941

https://blog.csdn.net/AWAY852/article/details/128180807

 

posted on 2023-05-15 16:54  06  阅读(500)  评论(0编辑  收藏  举报