To view the contents of a Docker image, you can use the docker run command to start a container from the image and then use commands such as ls or cat to view the contents of the container. If you prefer not to start the container, there is an option for docker image save command.
View contents while the container is running
Open your terminal and run the following command to start a container from the Docker image:
Replace
<container_name>with a name for your container, and<image_name>with the name of the Docker image you want to view the contents of.Once the container is running, you can use commands such as
lsorcatto view the contents of the container. For example, to list the contents of the root directory, you can run:This command will show you the files and directories in the root directory of the container.
You can also view the contents of a specific file by running the
catcommand followed by the path to the file. For example:Once you are done, you can stop and remove the container using the following command:
This will stop and remove the container from your system.
View contents without starting the container
Use the following command to directly save the contents of the image to a tar file:
You can also export the container's filesystem. If you don’t need to save or open the archive, instead preferring to get the file list in your terminal, modify the tar command:
Third option is to view the docker image history:
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.