ASP.NET Core apps in Docker core docker

Docker is an open-source containerization platform for building software. In Docker, an app is put to a Container along with all it’s dependencies. These are packed together as a Container Image. So, in short it means that Docker contains Containers and containers contain Images.

ASP.NET Core Docker

What is ASP.NET Core Docker? Suppose we have an ASP.NET Core App which we want to run on Docker. We can achieve this by putting the app along with Dot Net Core SDK (which is a dependency of the app) as an Image to the Container. So now our ASP.NET Core App will run from the container and not from the Operating System of our PC. When the ASP.NET Core app runs in Docker it will not need the following things:

  • 1. DOT NET installation on the PC.
  • 2. Operating system as docker is itself an operating system for the container.
  • 3. Any other dependency that the app has, as everything is put inside the container as images.

That sounds great, isn’t it?

In the below image we have explained this by showing 3 images contained by 3 containers of docker. These images can be any program with all it’s dependencies, and the programs executes directly from the container images without needing anything else. core docker tutorial

Docker Benefits for Developers

Docker provides a lot of benefits to developers. Some important ones are:

  • 1. Fast, easy and consistent delivery of apps.
  • 2. Responsive development and scaling of apps.
  • 3. Reduces cost of development of apps.

Fast, easy and consistent delivery of apps by using Docker

Since apps kept inside the containers can run on their own therefore developers can work directly on these containers. This comes out to be handy for continuous integration and continuous delivery (CI/CD) workflows.

Let us understand it with a simple example. Two people in a Product Development Company, Developer A who lives in Seattle & Tester B who lives in New York, are developing as ASP.NET Core APP. This app does a simple task of providing the current value of a stock listed on Nasdaq. The app contains a single page where users can enter a stock name (example Microsoft) and submit it by clicking a button. The app then calls an external REST API service which will return back the current price of the stock.

So, what happens here is, first Developer A develops this app in Docker, and ships the Docker Image of the app to Tester B. The shipment is not done physically through Post office or Fedex, as the containers are virtual in nature, so instead it can be done through internet just as emails are sent.

Fast development of apps with docker

Now Tester B, on receiving this image, puts the image inside a Docker Container. The container will have all the things required by the image like DOT NET, OS, etc. The tester runs the app from the container itself and does some tests. If the tests are failed then developer A has to fix them. When all the tests pass then the app becomes ready for deployment on production server.

Easy development of apps with docker

Finally, developer A puts the image on a Docker container in a cloud service provider like Azure, AWS or Google Cloud. The app then becomes live for people around the world. This is as simple as making a tea by yourself.

Consistent development of apps with docker

Responsive development and scaling of apps with Docker

Docker containers can run anywhere, like on laptop, on a virtual machine, on a data center or on a cloud provider. It is also very easy for scaling up the app or tearing it down.

Take for example, an app running inside 5 containers suddenly becomes very popular and starts getting huge traffic. So, we can increase the containers to 10 to fulfil its needs. In the same way we can reduce the containers from 5 to just 1 in-case if the traffic to the app becomes less.

docker app scaling

Reduces cost of development of apps by using Docker

Docker is lightweight and fast, it is a cost-effective alternative to hypervisor-based virtual machines and so will save our money. We also don’t need to install paid software’s like SQL Server on your pc as they can run from a docker container itself.

For example, we can download SQL Server image from the internet and put it inside a docker container. Now the SQL Server will run from a container itself and we will not need to install it on my pc. This saves us from buying the licence fee.

sql server docker container tutorial

Docker Architecture

Docker architecture is Client-Server type, there is a Docker Client component, which is also known as Docker CLI, and Docker Server component. The Docker Server is also called by another name Docker daemon (dockerd). We as users uses docker client to communicate with daemon to do tasks like creating containers with images, pulling and pushing images, and so on.

The Docker daemon does the heavy lifting tasks like managing images, containers, networks, and volumes. When we install docker on our local PC then both the Docker client and daemon gets installed on our local PC.

When deploying apps on Azure we use our docker client installed in our PC to connect with the daemon installed on Azure server and instruct it do operations for us.

Image, Container & Registries in Docker

A Docker Image contains the app along with it’s dependencies. Often these images are based on other images like we can have a ubuntu OS image where IIS and DOT NET SDKs are installed. Then we also have our ASP.NET Core app in that image.

An image is contained by a Docker Container. We can create, start, stop, move, or delete a container using commands send from the docker client to daemon. As already discussed, the container is self-sustained, that is an app can run from the container without needing anything else from the outside world.

A Docker Registry stores docker images. We can create a Docker Image on our local pc and then push these image on a docker registry. Now, once an image is stored in the docker registry then other people can pull that image from there, into their own local pc, and create a docker container containing that image. Do you remember the container delivery example “post office, Fedex” ? The Docker Registry fits there and the delivery of the Image is powered by it.

The 2 famous Docker Registry are:

Docker Hub contains millions of docker images which we can pull to your local pc and use them to create great apps.

In the below given image we have illustrated the working of Docker Registry.

docker registry

In the End

Docker is a great way to build app and you are going to love this platform. In this ASP.NET Core Docker Tutorial series, I will be teaching you docker from start till end. You will be learning how to create ASP.NET Core app inside Docker Containers and publish them on Azure.

Check our ASP.NET Core Docker Series: