随笔 - 105  文章 - 2 评论 - 9 阅读 - 19万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

随着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   06  阅读(754)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示