How to list all directories and files inside docker container?
Solution 1
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)
Solution 2
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
Related videos on Youtube
Comments
-
variable almost 2 years
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"......
- Run
docker run -it <container_id> dir
- Modify the dockerfile and add CMD at end of dockerfile -
CMD ["dir"]
, then rundocker run <container_id> dir
How to list all directories and files inside docker?
-
Andrei Mustata almost 4 yearsNote that
docker run
needs the image name, not a container ID. The image being the thing that you've just built based off of theDockerfile
, and the container being the thing that you ran, instantiating the image, so to say.
- Run