以下是我的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"......
docker run -it <container_id> dir
CMD ["dir"]
,然后运行docker run <container_id> dir
如何列出Docker内部的所有目录和文件?
在Dockerfile
中添加以下命令:
FROM python:3.6.5-windowsservercore
COPY . /app
WORKDIR /app
RUN dir #Added
RUN pip download -r requirements.txt -d packages
仅使用exec
命令。
现在因为您运行基于WindowsServercore的映像使用powershell
命令(而不是/bin/bash
,您可以在许多基于Linux的映像示例中看到该命令,并且在Windowsservercore上默认未安装基于图像),只需这样做:
docker exec -it <container_id> powershell
现在您应该获得一个迭代终端,您只需执行ls
或dir
就可以列出文件了>
顺便说一句,我发现了这个问题:
Exploring Docker container's file system
它包含大量的答案和建议,也许您可以在那里找到其他好的解决方案(例如,有一个非常友好的CLI工具可以探索容器:https://github.com/wagoodman/dive]