(C# ASP.NET Core) What is Docker, Dockerfile, DockerImage and Containerization?

This article is a beginner's introduction to the terminology associated with docker files, docker images and containers. I have kept the explanation bare simple so that it's easy to get started. I have tried to explain the most basic questions like what is a docker, what is it's use for you, and what the basic terms mean in nutshell.
(Rev. 04-Jun-2024)

Categories | About |     |  


Docker is like GitHub

Docker is a website like Github where developers can upload their ASP.NET Core (and of course, other projects) in a special, compressed format called Docker Image.

The website of the Docker company is https://www.docker.com/

To understand Docker, let us first recall how Github works. Github allows developers to upload their project files in source code form, as you must already be familiar. Other developers have to download (clone) those files to their respective computers and compile them with the help of compilers and IDE like Visual Studio. Hence, Github is a code sharing platform.

Now coming to Docker. Docker is also a code sharing platform, but Docker images are not in source code form - they are in a specially compressed form, called Docker Image. A developer creates an image (with various tools) and pushes it to her docker repository called DockerHub. Other developers can pull that docker image and run it directly, there is no need to compile it. The important thing here is: source code isn't shared; a ready-to-run image is shared with collaborating developers.

Video Explanation

Please watch the following youtube video:

How does Docker benefit me?

Firstly, it helps you collaborate with other developers who can pull and run your images on their development computers.

Secondly, a docker image can be pulled by AWS, Azure Container Registry, Google and other clouds to deploy it and connect it to domains so that the whole world can visit and use your asp.net core website, API, etc., (and of course, other projects). The exact process is different for each cloud, so you will have to spend time to consult their documentation for details.

Terminology: Dockerfile, Docker Image and Container

    Dockerfile → (build) → Image → (run) → Container

A Dockerfile is the starting point for building a docker image. You can right click your visual studio project to create a docker file (see the linked video in next tutorials).

A Dockerfile is a file that contains information about the various project files that have to be included in an image. Additionally, it also contains a list of other dependencies, other images. For example, your dotnet core app will be dependent on the runtime image "mcr.microsoft.com/dotnet/aspnet" provided by microsoft. The dependencies help reduce the size of your image. The Dockerfile has no extension and its name is "Dockerfile" - spellings and case matter.

A Docker Image is built from Dockerfile with the help of a command line + GUI program called "Docker Desktop". Docker Desktop can be obtained from https://www.docker.com/products/docker-desktop.

If you are using Visual Studio, then the whole process boils down to a few clicks. Visual Studio runs all the commands for you.

Linux/Windows Engine: A dotnet core project can either be based on a linux engine, or on a windows engine. When you create a new project in Visual Studio, then you will see a dropdown for docker support - linux, windows. This option is asked at the time of creation of a new project, but it can be changed later, by manually editing the csproj project file. Hence, the docker image will be based either on linux or windows - you will have to choose one of them. If you are on Windows 10 Home edition, then you should use the Linux Engine.

Now what is a container? You can think of a Docker Image as a blueprint, like we have a class in programming terminology. A docker image is a readonly structure. It needs instantiation, it needs to be run! An "object" has to be created - it has to be containerized.

Containerization is done by running a few commands through the docker desktop application.

A container is based on linux or windows engine as per the requirements of the docker image. A container uses the resources of your PC to run a linux/windows engine similar to a VM. A container also provides RW memory to load and execute your project.

This Blog Post/Article "(C# ASP.NET Core) What is Docker, Dockerfile, DockerImage and Containerization?" by Parveen is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.