Exploring Docker container’s file system

To explore a Docker container’s file system, you can use the following methods.

1. Direct Access to a Running Container

  • Run a shell inside the container
docker exec -it <container_name_or_id> /bin/bash

       or use /bin/sh if Bash is unavailable

docker exec -it <container_name_or_id> /bin/sh
  • Once inside, you can navigate the file system using typical Linux commands like lscdcat, etc.

2. Inspect Container’s File System Without Running It

  • Start the container if it’s stopped
docker start <container_name_or_id>
  • Use
docker exec -it <container_name_or_id> /bin/bash

3. Copy Files from the Container

  • Use the docker cp command to copy files from the container to your local system.
docker cp <container_name_or_id>:<path_in_container> <local_path>
  • Example
docker cp my_container:/etc/passwd ./passwd

4. Explore Using docker diff

  • Check for file system changes in the container
docker diff <container_name_or_id>
  • This will list added (A), deleted (D), and modified (C) files.

5. Export Container File System

  • Export the container’s file system as a tarball
docker export <container_name_or_id> -o container_fs.tar
  • Extract and explore the tarball locally
tar -xvf container_fs.tar

6. Mount Container Filesystem

  • Use docker commit to save the container as an image
docker commit <container_name_or_id> temp_image
  • Run a new container with an interactive shell from this image.

 

Share

Comments

One response to “Exploring Docker container’s file system”

  1. Yash Sharma

    This is a clear and practical guide to exploring a Docker container’s file system. The step-by-step methods make it easy for beginners and experienced users alike to understand and apply. I especially appreciate the inclusion of docker diff and docker export commands—they’re super useful for tracking changes and offline inspection. Thanks for sharing these valuable tips!

Leave a Reply

Your email address will not be published. Required fields are marked *