如何使用不同的命令启动已停止的 Docker 容器? [英] How to start a stopped Docker container with a different command?

查看:22
本文介绍了如何使用不同的命令启动已停止的 Docker 容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用不同的命令启动一个停止的 Docker 容器,因为默认命令会崩溃 - 这意味着我无法启动容器然后使用docker exec".

I would like to start a stopped Docker container with a different command, as the default command crashes - meaning I can't start the container and then use 'docker exec'.

基本上我想启动一个 shell,以便我可以检查容器的内容.

Basically I would like to start a shell so I can inspect the contents of the container.

幸运的是我使用 -it 选项创建了容器!

Luckily I created the container with the -it option!

推荐答案

查找已停止的容器 id

docker ps -a

提交停止的容器:

此命令将修改后的容器状态保存到新图像中 user/test_image

docker commit $CONTAINER_ID user/test_image

使用不同的入口点开始/运行:

docker run -ti --entrypoint=sh user/test_image

入口点参数说明:https://docs.docker.com/engine/reference/run/#/entrypoint-default-command-to-execute-at-runtime

上述步骤只是启动一个具有相同文件系统状态的停止容器.这对于快速调查非常有用.但是环境变量、网络配置、附加卷和其他人员不是继承的,您应该明确指定所有这些参数.

Steps above just start a stopped container with the same filesystem state. That is great for a quick investigation. But environment variables, network configuration, attached volumes and other staff is not inherited, you should specify all these arguments explicitly.

从这里借用了启动已停止容器的步骤:(最后一条评论)https://github.com/docker/docker/issues/18078

Steps to start a stopped container have been borrowed from here: (last comment) https://github.com/docker/docker/issues/18078

这篇关于如何使用不同的命令启动已停止的 Docker 容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆