如何列出Docker容器内的所有目录和文件?

问题描述 投票:0回答:2

以下是我的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 dockerfile docker-for-windows docker-container docker-image
2个回答
0
投票

Dockerfile中添加以下命令:

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

0
投票

仅使用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]

© www.soinside.com 2019 - 2024. All rights reserved.