Working with Docker can be a challenge for some developers, especially if it includes the process of setting up a Dockerfile.
First, it may be useful to know exactly what a Docker image is. In an AWS article, they define it as “an executable and standalone file used to create a container. This container image contains the libraries, dependencies, and files that the container needs to run.”
It is not possible to directly view the original Dockerfile
of an image unless the author has made it public (for example, on Docker Hub or in a GitHub repository). However, you can partially reconstruct the steps used to create the image using command-line tools.
docker history
to inspect the image
This command shows the image's layer history and the commands used to build it:
docker history --no-trunc image-name
You will see instructions like RUN
, COPY
, or CMD
, although in a simplified form. This does not generate a complete Dockerfile, but it gives you a good idea of how the image was built.
dive
Dive is an open-source tool that allows you to explore each layer of the image, view the added files, and analyze the size of each change.
Install and run it like this:
dive image-name
It’s ideal for understanding how an image is structured or auditing third-party images.
Many images on Docker Hub include links to their GitHub repository, where they often publish the original Dockerfile.
For example, the official NGINX image on Docker Hub: https://hub.docker.com/_/nginx points to this repository: https://github.com/nginxinc/docker-nginx
There you can find the Dockerfile in the root directory or in folders like /docker
.
Although you can reconstruct most of the build steps of an image, there are things you won’t be able to recover, such as:
ARG
used during build time.dockerignore
To find or reconstruct the Dockerfile of an image:
docker history
to view commands by layerdive
to understand the contents of each layer
Do you need help auditing existing images, migrating containers, or designing a more efficient and secure Dockerfile? At Rootstack, we help development teams modernize their Docker infrastructure and optimize their DevOps workflows. Let’s talk today.