我做了一个docker拉,可以列出下载的图像。我想看看这张照片的内容。在网上查了一下,但没有直接的答案。


当前回答

探索docker图像!

弄清楚里面是什么样的shell bash或sh…

首先检查镜像:docker Inspect name-of-container-or-image

在JSON返回中查找入口点或cmd。

然后执行:docker命令——rm -it——entrypoint=/bin/bash映像名称

进入后执行:ls -lsa或其他shell命令,如:CD ..

它代表互动…和遥控。rm表示运行后删除容器。

如果没有像ls或bash这样的常用工具,而你可以访问Dockerfile,简单地将常用工具作为一个层添加。 示例(alpine Linux):

RUN apk add --no-cache bash

当你无法访问Dockerfile时,只需从新创建的容器中复制/提取文件并查看它们:

docker create <image>  # returns container ID the container is never started.
docker cp <container ID>:<source_path> <destination_path>
docker rm <container ID>
cd <destination_path> && ls -lsah

其他回答

探索docker图像!

弄清楚里面是什么样的shell bash或sh…

首先检查镜像:docker Inspect name-of-container-or-image

在JSON返回中查找入口点或cmd。

然后执行:docker命令——rm -it——entrypoint=/bin/bash映像名称

进入后执行:ls -lsa或其他shell命令,如:CD ..

它代表互动…和遥控。rm表示运行后删除容器。

如果没有像ls或bash这样的常用工具,而你可以访问Dockerfile,简单地将常用工具作为一个层添加。 示例(alpine Linux):

RUN apk add --no-cache bash

当你无法访问Dockerfile时,只需从新创建的容器中复制/提取文件并查看它们:

docker create <image>  # returns container ID the container is never started.
docker cp <container ID>:<source_path> <destination_path>
docker rm <container ID>
cd <destination_path> && ls -lsah

我试过这个工具——https://github.com/wagoodman/dive 我发现探索docker映像的内容非常有帮助。

如果图像包含一个shell,您可以使用该图像运行一个交互式shell容器,并探索该图像所具有的任何内容。如果sh不可用,busybox ash shell可能可用。

例如:

docker run -it image_name sh

或者跟随带有入口点的图像

docker run -it --entrypoint sh image_name

或者,如果你想查看映像是如何构建的,也就是Dockerfile中的步骤,你可以:

docker image history --no-trunc image_name > image_history

这些步骤将被记录到image_history文件中。

如果你想检查图像内容而不运行它,你可以这样做:

$ sudo bash
...
$ cd /var/lib/docker  # default path in most installations
$ find . -iname a_file_inside_the_image.ext
... (will find the base path here)

这适用于当前默认的BTRFS存储驱动程序。

要列出映像的详细内容,您必须运行docker命令——rm image/name ls -alR,其中——rm表示一旦从容器中退出就立即删除。