如何访问Docker镜像?
我正在尝试访问一个docker镜像而不运行,我只是想知道它包含的validation。 我不能ssh进入容器,因为它在一秒钟结束,所以我需要探索图像,而不是容器。 或者在完成之前是否有权访问容器?
实际探索一个图像是非常麻烦的。 docker save
命令的输出不是很友好。 你最好用一个容器工作。 但是你不需要运行一个容器来做到这一点。
您可以使用docker create
命令和其他一些命令来浏览一个容器而不运行它:
docker pull alpine docker create --name foo alpine false docker export foo | # Export the entire filesystem as a tape archive tar -tf- | # Use tar to output the names of files less # pipe to less to page the output
如果你想检查一个文件,你可以使用docker cp
,如下所示:
docker cp foo:etc/passwd - | tar -xO | head -n3 root:x:0:0:root:/root:/bin/ash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin
在最后的陈述中你可以不用pipe道; 你会在顶部得到一些焦油垃圾,但是如果你只是在探索,这并不重要。
明白了,这是命令:
docker run -i -t image/container /bin/bash