How to Explore Docker container’s file system
Today in this article, we will see a few approaches how to explore the docker container’s file system.
We will see multiple methods of listing all directories and files inside the docker(run or stopped) container.
You might find the need to explore files from running containers or stopped containers on multiple occasions.
Today in this article, we will cover below aspects,
Using docker exec command to explore the file
docker exec command will run in the default directory of the container and it is mainly meant for running containers only.
Running this command on paused or stopped containers will result in an error.
Please make sure your docker running before executing the below commands.
Using Bash Shell
Command:
docker exec -it <container> bash
Let’s execute an interactive bash
shell on the container.
Example
docker exec -it 1cf2eafdee49 bash
OR
docker exec -t -i 1cf2eafdee49 bash
Please note to run the below command to get the details of all files and folders in the container file.
ls -all
Using Shell or Powershell command
Command:
docker exec -it <container> sh
OR
docker exec -it <container> sh
Let’s execute an interactive bash
shell on the container.
Example
docker exec -it 1cf2eafdee49 powershell
OR
docker exec -t -i 1cf2eafdee49 powershell
Using Copy Command to explore files
Alternatively, we can use the copy command to copy the containers file and use the new containers file system to explore the files.
This technique is also useful if containers are stopped or paused
docker cp <container>:<container-path> <host-path>
Below we are copying the file from the container to the host path. Once copied host path can be used to explore the files.
Below is now how you can check all the files and directory,
dir path
References:
Do you have any comments or ideas or any better suggestions to share?
Please sound off your comments below.
Happy Coding !!
Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.