What Happens During Docker Build and Run?
When using Docker, you will encounter two major operations `build` and `run`. The build command creates a docker image based on the `Dockerfile`. The run command uses the created docker image to run a
When using Docker, you will encounter two major operations build
and run
. The build command creates a docker image based on the Dockerfile
. The run command uses the created docker image to run a container.
But, what do these mean? What's an image? What does running a container mean?
To understand this question further, let's create a Docker image.
When building the image it starts with a base image followed by running each command in layers.
Docker Building Images
Dive a tool to dissect docker images into its layers gives us a sneak peek of what goes on when we docker build <image-path:tag>
Docker starts by spinning up the container of the base image and runs the next command on the file
Captures the files changed during this process along with metadata
The changed files called as changedset is stored in
layer.tar
and the associated metadata in layer.json
Jamie Duncan has dissected a Docker image in detail to understand the metadata and changeset better
Docker Running Containers
Tying it all together, Though there were container technologies before the Docker era, Docker made the process easy, maintainable, and reproducible.
When running a docker container by default
Creates a PID namespace to run all the processes inside the container
Allocates a default of 6m memory. A container can scale to use as much CPU as it needs.
Creates a thin Read-write layer on top of the image layers. This layer will hold all the data from writes inside the container.
Along with the above items, there is a tonne of other parameters that you can tweak when running a Docker container. Docker documentation has more info about it.
The namespace, allocated resources, and the R/W layer are all deleted when the container is removed.
Last updated