Member-only story
From Dockerfile to Production
Exploring the dizzying life of a Docker image
If you’re familiar with Docker, then you have likely have the commands docker build
and docker run
burned into your brain.
However, few people understand how they work.
The traits that have made Docker successful have also made it a blackbox — the convenience and abstractions. These commands accomplish many things, but Docker deftly hides this complexity so you can focus on other things.
But if you’re like me, you love to learn more about how the tools you use work. So come with me on a journey as we explore the depths of Docker.
In this post, you’ll learn exactly how Docker converts a Dockerfile into an image, and how that image makes it’s way into production.
Let’s dive in.
The Dockerfile is the DNA
The Dockerfile can be thought of as the DNA of a container image. It has the instruction set needed to generate and recreate an image.
When you run docker build
, Docker reads and parses the Dockerfile to create the instruction set. Each line of the Dockerfile defines a command that must be run in order to create the image.
For example:
RUN apt-get install -y git
will download the git
binary into the image.
After Docker parses the file, each command is then sent to the Docker daemon to be executed.
The Docker daemon
If the Dockerfile is the DNA, then the Docker daemon is the ribosome.
Just as ribosomes use the instructions in DNA to create the proteins that make up enzymes, the Docker daemon uses the instructions from the Dockerfile to create the layers that make up the container image.
And just like biology, Docker’s image building process is quite fascinating and involved.