How to Explore Docker Container’s File System?

Better Stack Team
Updated on August 1, 2022

If you want to explore the Docker container’s file system, you can use on of the following methods.

Using the docker exec command

Docker version 1.3 or newer supports the docker exec command. This command can run new process in an already running container. This means you can run bash /bin/bash in the container state like this:

docker exec -t -i container_name /bin/bash
Copied!

Using Snapshotting

You can evaluate the docker file system by following these steps:

  1. Find the id of your running container
docker ps
Copied!
  1. Create an image (snapshot) from the container file system
docker commit 12345678904b5 mysnapshot
Copied!
  1. Explore the file system using the bash
docker run -t -i mysnapshot /bin/bash
Copied!

This way, you can evaluate the filesystem of the running container at the precise time moment. The container is still running, no future changes are included.

To delete the snapshot, run the following command:

docker rmi mysnapshot
Copied!

Using the ssh

If you want a continuous access to the docker file system, you can install the sshd to your container and run the sshd daemon:

docker run -d -p 22 mysnapshot /usr/sbin/sshd -D
Copied!

To see to which port to connect, run the following command:

docker ps
Copied!
Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

We are hiring.

Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.

Explore all positions →

Reliability is the
ultimate feature

Delightful observability tools that turn your logs & monitoring into a secret weapon for shipping better software faster.

Explore Better Stack