6

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
  • 1,013
  • 1
  • 9
  • 21
variable
  • 8,262
  • 9
  • 95
  • 215
  • 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

4 Answers4

9

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
  • 3,312
  • 4
  • 17
  • 40
8

This is what I found helpful in the end. Thanks to Nischay for leading the way. The great thing about this, of course, is that one may examine the files even if the publish fails at a later stage.

# Copy everything...
COPY . ./
# See everything (in a linux container)...
RUN dir -s    
# OR See everything (in a windows container)...
RUN dir /s
Dave
  • 3,093
  • 35
  • 32
4

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
  • 3,206
  • 12
  • 23
2

To list all of files and directories in side docker you can use DOCKER_BUILDKIT=0 command in front of the command to build the docker. For example: DOCKER_BUILDKIT=0 docker build -t testApp .

1. inside the Dockerfile you can add RUN ls to your Dockerfile in which ls stand for list, it should be like this:

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

2. Then execute your Dockerfile with the command DOCKER_BUILDKIT=0 docker build -t any_of_your_docker_image_name .

Let's me know if this address your expectation.

Chanrithisak Phok
  • 1,590
  • 1
  • 19
  • 29