
How to view or recreate the Dockerfile from an image
Table of contents
Quick Access

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.”

How to Find the Dockerfile of an Image?
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.
1. Use 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.
2. Explore the image with 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.
3. Search for the source repository
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
.

Important
Although you can reconstruct most of the build steps of an image, there are things you won’t be able to recover, such as:
- Dockerfile comments
- Values of
ARG
used during build time - Files ignored by
.dockerignore
- Sensitive data or secrets
Summary
To find or reconstruct the Dockerfile of an image:
- Use
docker history
to view commands by layer - Explore with
dive
to understand the contents of each layer - Check Docker Hub or GitHub for the original Dockerfile if available
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.
We recommend this video