2

Following is my dockerfile:

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

To get list of files in the image, I have tried both the following options, but there is error:

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. Run docker run -it <container_id> dir
  2. Modify the dockerfile and add CMD at end of dockerfile - CMD ["dir"], then run docker run <container_id> dir

How to list all directories and files inside docker?

Andrei Mustata
  • 820
  • 1
  • 8
  • 19
variable
  • 6,123
  • 5
  • 52
  • 127
  • Note that `docker run` needs the image name, not a container ID. The image being the thing that you've just built based off of the `Dockerfile`, and the container being the thing that you ran, instantiating the image, so to say. – Andrei Mustata Jun 01 '20 at 10:00

2 Answers2

6

Simply use the exec command.

Now because you run a windowsservercore based image use powershell command (and not /bin/bash which you can see on many examples for linux based images and which is not installed by default on a windowsservercore based image) so just do:

docker exec -it <container_id> powershell

Now you should get an iteractive terminal and you can list your files with simply doing ls or dir

By the way, i found this question :

Exploring Docker container's file system

It contains a tons of answers and suggestions, maybe you could find other good solutions there (there is for example a very friendly CLI tool to exploring containers : https://github.com/wagoodman/dive)

jossefaz
  • 2,450
  • 1
  • 11
  • 30
1

In your Dockerfile add the below command:

FROM python:3.6.5-windowsservercore
COPY . /app
WORKDIR /app
RUN dir #Added
RUN pip download -r requirements.txt -d packages
nischay goyal
  • 2,692
  • 9
  • 21