Docker Fundamentals Using Docker Desktop

What is Docker?

Docker is an open platform that is used for developing, shipping, and running applications. Docker has the ability to package and run an application in a loosely isolated environment called a container. The container is an isolated and lightweight environment for hosting our applications.

Docker is a tool that is used to containerize our application. It takes care of creating and managing containers.

Benefits of Containerization

Isolation

When we are deploying multiple applications on the same server, there might be cases that one or more apps have a dependency on the same third-party library but each app may require a different version of the same library. In this case, some apps may stop working due to dependency on a particular version.

If we use docker then this problem is resolved. Docker creates containers and each container will have a particular app and its associated third-party libraries. Each app will run in its own container and they will be isolated from each other.

Portability

It is very easy to port our applications between multiple environments. An image is created from the project source code which includes a list of all dependencies and we can create a container from that image in any environment and run the container.

Consistency

If your application runs inside a container on the local system without any issue then it will run everywhere inside the container.

Image - Image is a read-only template that has instructions that are required to create a container. Image is an executable package that includes everything needed to run an application – including the code, runtime, and libraries. We can create multiple containers running concurrently from the same image.

Container - A container is a runtime instance of an image. The container is a process that is created from the image using Docker.

Docker Fundamentals Using Docker Desktop

Docker Registries - All images are stored in registries. The registry can be public or private just like Github. Docker Hub is the most popular registry.

What is the difference between Docker and Container?

Docker is a platform for managing containers while a container is a process that executes our applications.

Docker Engine

There are two parts of Docker Engine,

  1. Client
  2. Server

The client interacts with the server using REST API. The server is also known as Docker Daemon. We use Docker CLI to interact with the server. Here Docker CLI is the client.

How to install Docker

Please make sure Hyper-v should be enabled in your system. Windows 10 Professional or Enterprise version is suitable for Docker Desktop.

Go to control panel >> Programs >> Programs and features and click on ‘Turn Windows features on or off.

Docker Fundamentals Using Docker Desktop

Make sure that Hyper-V is installed. Select Hyper-V if it is not selected and install it.

Below is the URL of Docker Desktop for windows. Download it and install.

https://docs.docker.com/desktop/windows/install/

If you get an exception while starting Docker Desktop after installation then visits the below URL,

https://docs.microsoft.com/en-us/windows/wsl/install-win10#step-4---download-the-linux-kernel-update-package

Follow the instructions to complete the setup listed in the above URL.

Open Windows PowerShell and type the below command to check the docker version

docker --version

Use the below command to see all images

docker images

Currently, we don’t have any images on the local system so no image is displayed.

To check the containers, use the below command,

docker ps –a

Download an image from the registry

https://hub.docker.com/_/microsoft-dotnet-samples

Open Powershell and run the below command to download the image,

docker pull mcr.microsoft.com/dotnet/samples:dotnetapp

Now run the command to see images,

docker images

Below is the output, currently we have only 1 image.

Docker Fundamentals Using Docker Desktop

Now download another image,

docker pull mcr.microsoft.com/dotnet/samples:aspnetapp

Now view images again,

docker images

Docker Fundamentals Using Docker Desktop

Now you can see there are 2 images.

Create a container from the image and run,

docker run -p 8000:80 --name aspnetcore_sample mcr.microsoft.com/dotnet/samples:aspnetapp

Here we have mapped port 80 of the container to our local system port 8000

Now go to Docker Dashboard by right click on the Docker icon in the taskbar and select Dashboard as displayed below screenshot.

Docker Fundamentals Using Docker Desktop

Docker Fundamentals Using Docker Desktop

You will see the container listed on the dashboard

Click on the highlighted option (as displayed in the above image) to view it in the browser.

Docker Fundamentals Using Docker Desktop

In this article, we have learned the fundamentals of Docker. In the next part, we will see image creation from the ASP.Net Core project and we will create a container from that image.

Thanks for reading.


Similar Articles