Now we know how to download & run docker images. Now let's see how can we build them.
There are typically two ways to build a docker image.
Docker Commit
First is to run a Docker container as we’ve done in hello world example, and later make changes into it & commit our changes using docker commit
command. The Commit saves your changes to the new image layer.
DockerFile
The second way to build a docker is using the DockerFile
. DockerFile
is referred to as the blueprint or recipe book of the docker image. For instance node has package.json
, PHP has composer.json,
similarly for managing third party tools in our project, we use DockerFile
which manages the step by step guidelines for those tools.
DockerFile
is a simple text file & contains build steps for your application. Each actionable step in the DockerFile
becomes a separate layer in docker image.
Which method to use for building?
Well, in real world, Docker Commit has a very little place and isn’t really a popular choice. On the other hand, DockerFile
is superior & you should go for it too.
Digging in the Docker Image
Docker images consists of layers. Each layer composed of self-contained files & the docker image is the result of one or more layers.