我做了一个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

有一个叫做anchor - cli的免费开源工具可以用来扫描容器图像。这个命令将允许您列出容器映像中的所有文件

anchore-cli image content myrepo/app:latest files

https://anchore.com/opensource/

编辑:不再从anchore.com,这是一个python程序,你可以从https://github.com/anchore/anchore-cli安装

docker save nginx > nginx.tar
tar -xvf nginx.tar

有以下文件:

清单。json -描述具有Container属性的文件系统层和json文件的名称。 .json -容器属性 -每个“layerid”目录包含json文件,描述与该层相关的层属性和文件系统。Docker将容器映像存储为层,通过跨映像重用层来优化存储空间。

https://sreeninet.wordpress.com/2016/06/11/looking-inside-container-images/

OR

您可以使用dive与TUI交互查看图像内容

https://github.com/wagoodman/dive

如果你想在不启动容器的情况下列出镜像中的文件:

docker create --name listfiles <image name>
docker export listfiles | tar -t
docker rm listfiles

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