Dockerize Asp Dotnet Application

what is Docker

Docker is a set of the platform as a service (PaaS) service is a category of cloud computing services that provides a platform allowing customers to develop, run, and manage applications without the complexity of building and maintaining the infrastructure typically associated with developing and launching app products that use OS-level virtualization is an operating system paradigm in which the kernel is a computer program at the core of a computer’s operating system that has complete control over everything in the system. It is the “portion of the operating system code that is always resident in memory”, and facilitates interactions between hardware and software components.

allows the existence of multiple isolated user-space instances. In such instances, called containers ( Docker ) OS-level virtualization is a technology that partitions the operating system to create multiple isolated Virtual Machines (VM). An OS-level VM is a virtual execution environment that can be forked instantly from the base operating environment. OS-level virtualization has been widely used to improve security, manageability, and availability to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries, and configuration files; they can communicate with each other through well-defined channels. Because all of the containers share the services of a single operating system kernel, they use fewer resources than virtual machines.

Docker architecture

Docker uses a client-server architecture. The Docker client talks to the Docker daemon, which does the heavy lifting of building, running, and distributing your Docker containers. The Docker client and daemon can run on the same system, or you can connect a Docker client to a remote Docker daemon. The Docker client and daemon communicate using a REST API, over UNIX sockets, or a network interface. Another Docker client is Docker Compose, that lets you work with applications consisting of a set of containers.

The Docker daemon

The Docker daemon (dockerd) listens for Docker API requests and manages Docker objects such as images, containers, networks, and volumes. A daemon can also communicate with other daemons to manage Docker services.

The Docker client

The Docker client (docker) is the primary way that many Docker users interact with Docker. When you use commands such as docker run, the client sends these commands to dockerd, which carries them out. The docker command uses the Docker API. The Docker client can communicate with more than one daemon.

Docker registries

A Docker registry stores Docker images. Docker Hub is a public registry that anyone can use, and Docker is configured to look for images on Docker Hub by default. You can even run your own private registry.

When you use the docker pull or docker run commands, the required images are pulled from your configured registry. When you use the docker push command, your image is pushed to your configured registry.

Docker objects

When you use Docker, you are creating and using images, containers, networks, volumes, plugins, and other objects. This section is a brief overview of some of those objects.

1. Images

Images are nothing but a read-only binary template that can build containers.

Often, an image is based on another image, with some additional customization. For example, you may build an image which is based on the centos image , configuration details needed to make your application run. You might create your own images or you might only use those created by others and published in a registry. To build your own image, you create a Dockerfile with a simple syntax for defining the steps needed to create the image and run it. Each instruction in a Dockerfile creates a layer in the image. When you change the Dockerfile and rebuild the image, only those layers which have changed are rebuilt. This is part of what makes images so lightweight, small, and fast, when compared to other virtualization technologies.

2. Containers

A container is a runnable instance of an image. You can create, start, stop, move, or delete a container using the Docker API or CLI. You can connect a container to one or more networks, attach storage to it, or even create a new image based on its current state.

By default, a container is relatively well isolated from other containers and its host machine. You can control how isolated a container’s network, storage, or other underlying subsystems are from other containers or from the host machine. For example

3. Networks

Docker networking is a passage through which all the isolated container communicate. There are mainly five network drivers in docker:

  1. Bridge: It is the default network driver for a container. You use this network when your application is running on standalone containers, i.e. multiple containers communicating with the same docker host.
  2. Host: This driver removes the network isolation between docker containers and docker host. You can use it when you don’t need any network isolation between host and container.
  3. None: This driver disables all the networking.
  4. macvlan: This driver assigns mac address to containers to make them look like physical devices. It routes the traffic between containers through their mac addresses. You use this network when you want the containers to look like a physical device, for example, while migrating a VM setup.

Install Docker Engine on CentOS


Install the yum-utils package (which provides the yum-config-manager utility) and set up the stable repository.

# sudo yum install -y yum-utils

# sudo yum-config-manager \

— add-repo \


  1. Install the latest version of Docker Engine and containerd, or go to the next step to install a specific version:
    # sudo yum install docker-ce docker-ce-cli
  2. Now let start and enable docker serves

# systemctl enable — now docker.service

Build Your Own Images

Docker builds images automatically by reading the instructions from a Dockerfile is

text file that contains all commands, in order, needed to build a given image for example now you have a simple Scenario that will publish core app on docker container using image base on centos image using Docker file

FROM centos

RUN yum update -y && yum install git wget -y && \

rpm -Uvh && \

yum install -y dotnet-sdk-3.1&& \

mkdir -p /work && git clone — depth 1 — branch asp1 && \

cd docker_by_doing/asp/ && dotnet publish -c release -o /work -r linux-x64 — self-contained


ENTRYPOINT [“dotnet”, “asp.dll”]

  • FROM creates a layer from the centos Docker image.
  • RUN same command for install and update and create same directory the build the app
  • WORKDIR the directory that will work when the container is start .
  • ENTRYPOINT the command that will run when container is start .

Lets build container

# .docker build -t asp .

The docker build command builds an image from a Dockerfile and a context.

Lets run container

# docker run -d — name web — network host asp

  • run .processes in isolated containers. A container is a process which runs on a host
  • -d detached
  • — name of the container
  • — network select the network driver
  • asp select the image that will create from docker file

Note you will find all example here

the resources for start learning docker is

docker quick start

dca ( docker certification admin )

docker deep dive




The DevOps Engineer helps increase speed of delivery, improve quality/security of code

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Critical R Studio Concepts You Must Know

The Data Æther

Method Access Control in Ruby

Whiteboard interviews suck! (but you should practice anyway)

This week in #Scala (May 31, 2021)

Starting Javascript

Singleton… How to test a Controller ?

Scheduling in Enterprise Clouds

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Haider Raed

Haider Raed

The DevOps Engineer helps increase speed of delivery, improve quality/security of code

More from Medium

Configure SonarQube on Azure DevOps Pipeline

Easily Create Azure VM Custom Linux Images for ASP.NET Core Services with GitHub Actions and Packer

Deploying a .NET 6 Web API and a MySQL Database with Azure Pipelines

Secure Azure Storage API