How to Explore Docker Container’s File System?

Better Stack Team
Updated on February 4, 2023

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

Using Snapshotting

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

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

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

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

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

docker ps

If you are new to Docker, feel free to start with our Getting started logging guide.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github