How to See Docker Image Contents
TLDR
To see what's inside a Docker image, use docker run
with an interactive shell, or inspect layers with docker history
and docker image inspect
. This helps you debug, verify, or explore images before running them.
Prerequisites
- Docker installed
- Terminal access
Start a Shell Inside the Image
The most direct way to explore an image is to start a container with an interactive shell. This lets you browse files and directories as if you were inside a running system.
# Start a shell in the image (replace with your image name)
docker run --rm -it nginx:alpine sh
Now you can use commands like ls
, cat
, or find
to look around. This is great for checking configuration files or installed binaries.
Inspect Image Layers and Metadata
You can see the history of how an image was built and its metadata using these commands:
# Show the image build history
docker history nginx:alpine
# Inspect detailed metadata
docker image inspect nginx:alpine
This gives you insight into each layer and the commands used to build the image.
Extract Files Without Running a Container
If you want to extract files from an image without running it, you can use a temporary container and the docker cp
command:
# Create a stopped container from the image
container_id=$(docker create nginx:alpine)
# Copy a file or directory from the container
docker cp $container_id:/etc/nginx/nginx.conf ./nginx.conf
# Remove the temporary container
docker rm $container_id
This is handy for debugging or retrieving configuration files.
Next Steps
Try exploring different images, or automate these checks in your CI pipeline to catch issues early.
Good luck with your project!
Found an issue?