variable
variable

Reputation: 9724

How to list all directories and files inside docker container?

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?

Upvotes: 13

Views: 131248

Answers (4)

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.

Upvotes: 4

Dave
Dave

Reputation: 3301

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

Upvotes: 8

jossefaz
jossefaz

Reputation: 3952

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)

Upvotes: 9

nischay goyal
nischay goyal

Reputation: 3480

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

Upvotes: 4

Related Questions