Exploring Docker container's file system
Here are a couple different methods...
A) Use docker exec (easiest)
Docker version 1.3 or newer supports the command exec
that behave similar to nsenter
. This command can run new process in already running container (container must have PID 1 process running already). You can run /bin/bash
to explore container state:
docker exec -t -i mycontainer /bin/bash
see Docker command line documentation
B) Use Snapshotting
You can evaluate container filesystem this way:
# find ID of your running container:
docker ps
# create image (snapshot) from container filesystem
docker commit 12345678904b5 mysnapshot
# explore this filesystem using bash (for example)
docker run -t -i mysnapshot /bin/bash
This way, you can evaluate filesystem of the running container in the precise time moment. Container is still running, no future changes are included.
You can later delete snapshot using (filesystem of the running container is not affected!):
docker rmi mysnapshot
C) Use ssh
If you need continuous access, you can install sshd to your container and run the sshd daemon:
docker run -d -p 22 mysnapshot /usr/sbin/sshd -D
# you need to find out which port to connect:
docker ps
This way, you can run your app using ssh (connect and execute what you want).
D) Use nsenter
Use nsenter
, see Why you don't need to run SSHd in your Docker containers
The short version is: with nsenter, you can get a shell into an
existing container, even if that container doesn’t run SSH or any kind
of special-purpose daemon
Exploring Docker container's file system
Here are a couple different methods...
A) Use docker exec (easiest)
Docker version 1.3 or newer supports the command exec
that behave similar to nsenter
. This command can run new process in already running container (container must have PID 1 process running already). You can run /bin/bash
to explore container state:
docker exec -t -i mycontainer /bin/bash
see Docker command line documentation
B) Use Snapshotting
You can evaluate container filesystem this way:
# find ID of your running container:
docker ps
# create image (snapshot) from container filesystem
docker commit 12345678904b5 mysnapshot
# explore this filesystem using bash (for example)
docker run -t -i mysnapshot /bin/bash
This way, you can evaluate filesystem of the running container in the precise time moment. Container is still running, no future changes are included.
You can later delete snapshot using (filesystem of the running container is not affected!):
docker rmi mysnapshot
C) Use ssh
If you need continuous access, you can install sshd to your container and run the sshd daemon:
docker run -d -p 22 mysnapshot /usr/sbin/sshd -D
# you need to find out which port to connect:
docker ps
This way, you can run your app using ssh (connect and execute what you want).
D) Use nsenter
Use nsenter
, see Why you don't need to run SSHd in your Docker containers
The short version is: with nsenter, you can get a shell into an
existing container, even if that container doesn’t run SSH or any kind
of special-purpose daemon
How to access docker's container file system
The docker export
command is what you are after. It will print on the standard output the content of a container filesystem as a tar archive.
docker export <container_name> > my_container.tar
or
docker export --output="my_container.tar" <container_name>
How to see docker image contents
You can just run an interactive shell container using that image and explore whatever content that image has.
For instance:
docker run -it image_name sh
Or following for images with an entrypoint
docker run -it --entrypoint sh image_name
Or if you want to see how the image was build, meaning the steps in its Dockerfile
, you can:
docker image history --no-trunc image_name > image_history
The steps will be logged into the image_history
file.
Docker container file system access
You could mount a volume on the container, so the "locally" generated docker files can be accessed from the host. For example:
docker run -v host_dir:container_dir yourDocker (...)
Your docker's process will save the files to his local container_dir
, and you could access them via your host's host_dir
.
How to view files inside docker image without running it?
Answering my own question.
you can add something like to override the entry point in the Dockerfile and run ls
or cat
command to see inside.
ENTRYPOINT ls /etc/fluentd
Related Topics
Kernel Stack and User Space Stack
Convert Xlsx to CSV in Linux With Command Line
How to Syntax Check a Bash Script Without Running It
Determine Direct Shared Object Dependencies of a Linux Binary
How to Convert Hex to Ascii Characters in the Linux Shell
How to Extract Duration Time from Ffmpeg Output
When Should I Wrap Quotes Around a Shell Variable
What Happens If You Use the 32-Bit Int 0X80 Linux Abi in 64-Bit Code
Redirect Stderr/Stdout of a Process After It's Been Started, Using Command Line
Command Not Found When Using Sudo
Makefiles With Source Files in Different Directories
Linux: Copy and Create Destination Dir If It Does Not Exist
How to Copy Commits from One Git Repo to Another
Static Link of Shared Library Function in Gcc