【问题标题】:How to list all directories and files inside docker container?如何列出 docker 容器中的所有目录和文件?
【发布时间】:2020-09-19 13:58:34
【问题描述】:

以下是我的 dockerfile:

FROM python:3.6.5-windowsservercore
COPY . /app
WORKDIR /app
RUN pip download -r requirements.txt -d packages

为了获取图片中的文件列表,我尝试了以下两个选项,但出现错误:

encountered an error during CreateProcess: failure in a Windows system call: 
The system cannot find the file specified. (0x2) extra info: 
{"CommandLine":"dir","WorkingDirectory":"C:\\app"......
  1. 运行docker run -it <container_id> dir
  2. 修改dockerfile并在dockerfile末尾添加CMD - CMD ["dir"],然后运行docker run <container_id> dir

如何列出docker内的所有目录和文件?

【问题讨论】:

  • 请注意,docker run 需要图像名称,而不是容器 ID。图像是您刚刚基于Dockerfile 构建的东西,容器是您运行的东西,实例化图像,可以这么说。

标签: docker dockerfile docker-for-windows docker-container docker-image


【解决方案1】:

只需使用exec 命令。

现在,因为您运行的是 基于 windowsservercore 的映像,所以使用 powershell 命令(而不是 /bin/bash,您可以在许多基于 linux 的映像示例中看到它默认情况下未安装 在基于 windowsservercore 的图像上)这样做:

docker exec -it <container_id> powershell

现在你应该得到一个迭代终端,你可以简单地通过 lsdir 列出你的文件

顺便说一句,我发现了这个问题:

Exploring Docker container's file system

它包含大量的答案和建议,也许您可​​以在那里找到其他好的解决方案(例如,有一个非常友好的 CLI 工具来探索容器:https://github.com/wagoodman/dive

【讨论】:

    【解决方案2】:

    在您的Dockerfile 中添加以下命令:

    FROM python:3.6.5-windowsservercore
    COPY . /app
    WORKDIR /app
    RUN dir #Added
    RUN pip download -r requirements.txt -d packages
    

    【讨论】:

      猜你喜欢
      • 2012-11-14
      • 2016-01-16
      • 2014-10-16
      • 1970-01-01
      • 2011-03-13
      • 2014-03-08
      相关资源
      最近更新 更多