Let us introduce ourselves to the Docker Hub and learned that it is a cloud-based centralized resource for container image discovery, image building, and distribution of those images. We also learned that a docker image is a multi-layer image on top of a base image. That said, using a base image removes the hassle of creating from scratch a suitable OS for docker image and gives us the option to customize the upper layers where our software will reside.
To create a custom image by using a base image, we need to provide the docker engine with instructions on how to install and configure packages and files and also some settings that go with it. These instructions are written in a plain text file called “dockerfile”. Dockerfiles are like recipes that you hand over to a chef and he/she cooks you a great meal. These docker files are written using a simple, descriptive set of steps that are called “instructions”. Each instruction creates a new layer in our image. Instructions include actions like running a command, adding a file or directory, what process to run when launching a container from the image, etc. This process is just like you would set a series of commands in a shell script. Once you request the building of an image, the Docker reads the dockerfile executes the instructions, and returns a final image.
Building a Docker Image
There are two ways of building your custom Docker image. You can either build it on your computer or you can use the Docker Hub that we talked about previously. In this part, we will learn how to build our Docker image locally and then publish it on the Docker Hub Registry.