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
ls,cd,cat, 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 cpcommand 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 committo 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.

Leave a Reply