问题描述
我有一个从Docker集线器拉出的Docker映像。
I have a Docker image that I pulled from Docker hub.
当我运行 docker run image_name
时,容器会立即退出。
When I run docker run image_name
, container exits immediately.
我无权访问Docker映像的源代码,包括Dockerfile。我所拥有的只是我从 hub.docker.com
中提取的图像。
I don't have access to the source code of the Docker image, including Dockerfile. All I have is an image I pulled from hub.docker.com
.
我需要调试/看看有什么
I need to debug/see what is inside the image (e.g. see and explore image's filesystem), without running it as a container.
是否可以?
推荐答案
从所需的映像启动容器,如下所示:
Start a container from desired image like this:
docker run -it- rm image_name bash
-i
即使未连接STDIN也保持打开状态
-i
Keeps STDIN open even if not attached
-t
分配一个伪tty
-rm
修剪在退出后停止容器
--rm
prunes stopped container after exit
bash
执行特定操作容器中的命令。您可以执行任何有效的命令。
bash
executes the specific command in the container. You can execute any valid command.
示例 docker run -it --rm --centos:7 pwd
输出 /
(根目录)。
更新:在某些情况下,图像的入口点使用 bash / sh -c 格式( docker run -it --rm image_name bash
)将不起作用,因为 bash
将被视为图像原始入口点的附加参数。
Update: In some cases, where image's entrypoint uses bash/sh -c
format above command(docker run -it --rm image_name bash
) will not work because bash
will be treated as additional argument to image's orignal entrypoint.
在这种情况下,您可以使用-entrypoint
标志以实现相同的结果:
In such case you can use the --entrypoint
flag for achieving the same result:
docker run -it --entrypoint "/bin/bash" image_name
这篇关于如果容器立即退出,是否探索Docker的映像文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!