Diving Into Docker With ASP.NET Core - Part One

In this series, we will see some of the Docker terms and Docker files, we will go through what Docker images are, and some Docker commands and data storage.

Docker is one of the greatest things that has happened in the past few years. It is a containerization platform that packages your application and all its dependencies together in the form of a Docker container.

Containers are highly useful for improvising security, reproducibility, and scalability in software development. Their rise is one of the most important trends in technology today.

If you are a software developer or data scientist or aspiring to it, Docker is your future. I will not go deep into the basics of what Docker is in this article; you can check my previous article, Overview of Docker, for that.

By the end of this series and with a little hands-on, you will have enough knowledge to use Docker.

OK, let us start with understanding some of the Docker terminologies.

Docker terminology

Docker Container

We can say that container is something which holds some stuff; it can be anything. Something is either inside it or either outside it. We can relate it with almost everything we use in our daily life.

Diving Into Docker With ASP.NET Core
The above image represents a normal storage container that we generally use in our daily life.
  • It can be used to store anything, right?

    Relating to Docker - you can store some information inside it.
  • It is portable; you can carry it anywhere you want.

    Relating to Docker - It can be used on your local machine, your friend's or coworker's machine, or on a cloud (Azure or AWS).
  • Has clear interface, you can open the lid, put anything, can close the lid again.

    Similarly, a Docker container also has several mechanisms for interfacing with the outside world. It has ports that can be open to interacting with the outside world.
  • Can be obtained from anywhere. You can buy an empty container from amazon.com or any other marketplace. Amazon gets its plastic container from manufacturers who stamp them out with a single mold.

    Relating to Docker, an offsite registry keeps an image. You can relate it with the mold in the example above. So, the registry is like a mold and whenever you need, you can just make one from the image.
Docker Image

Docker images are like a blueprint. I am quite sure that many of us have used a Nero image that we used to have a blueprint of our compact disk on our system and whenever we needed, we just had to burn it to a new disk.

Similarly, Docker images are immutable master templates that are used to pump out containers that are all exactly alike.

However, you must be wondering what the contents of the Docker image are?

Well, it contains, Docker files, libraries, and the code your application needs to run, all bundled together. Now, you are familiar with libraries and code, but what is a Docker file? Docker file is a file that contains instructions for how Docker should build your image. It refers to a base image that is used to build an initial image layer.

Let us say you have a Docker file for a machine learning application. Therefore, your file will tell Docker to add “pandas” as an intermediate layer and then, there will be a writable layer stacked on top of all other layers.

I am feeling very hungry now; I just ordered a pizza. I wonder if that pizza person will comes in 30 minutes. OK, let’s cook our pizza with Docker. You can relate the cooking of pizza to Docker.

Let’s start!

We need some basic things to start with the “recipe” and need the most important “ingredients”.

Pizza Docker
Recipe Docker file, it tells the step-by-step process to achieve your goal.
Ingredients (crust, sauce, cheeses, toppings) Docker Image that has the recipe and ingredients as well.

Combining both of the things, you will get the best ready-to-make kit for your pizza, and in case of Docker, you will get a Docker Image.

Now, let us look into what our recipe says.

It says -

Steps Process Pizza/Docker

Diving Into Docker With ASP.NET Core Build crust first, it is a base. While in Docker, we can relate it with basic parent image, Ubuntu. It is a bottom layer and will be built first.

Diving Into Docker With ASP.NET Core It is time to add some cheese as a second layer to our pizza. In Docker, it is like adding an external library like “Pandas”.

Diving Into Docker With ASP.NET Core Now sprinkle some toppings that you want to our pizza, In Docker, it is like adding a code file that you wrote to run your application.

Diving Into Docker With ASP.NET Core Now, add it to the oven, the oven can be treated as a Docker platform. You installed Docker to your computer so that you can cook up containers.
5. Diving Into Docker With ASP.NET Core Now, turn on your oven to cook pizza, in Docker you have to run the command “docker run [docker-iamge]”. It creates and starts your container.

Our Pizza and Docker Container is now cooked! Enjoy.

In Part 2, we will have a look at the tremendous power of Docker when combined with ASP.NET.