Why docker the docker cli through examples – code maze gas engine tom

Now that we have prepared our ASP.NET Core application, we are going to learn how to install and use Docker on Windows 10, the reasons behind using Docker, and some useful Docker CLI commands. Understanding how the Docker CLI works is crucial, and you’ll most definitely have a hard time proceeding to the next part without getting a grasp of the basic commands Docker offers through its powerful CLI.

As you know, Docker images consist of a bunch of layers witch attribute to the final environment inside that image. There are a lot of predefined images we can pull from the Docker Hub, but we can also make our own images by adding our layers on top of existing ones to create an image that suits our needs.

On Windows 10, Docker lets you choose between Linux and Windows containers, which is a very nice feature. In this series, we are going to stick with the Linux containers since Windows containers still have some compatibility issues, but the principles apply both on Windows or Linux containers. The syntax and underlying architecture (eg. paths) may vary a bit. Why Docker?

When we started learning Docker, the main problem we had was to grasp the big picture. It looked like just some complicated tool that produces an overhead in our projects. We’ve been already familiar with continuous integration and delivery, and Docker didn’t seem to fit into our CI/CD pipelines.

Let’s say you have a Java-oriented friend and you want to explain to him why .NET Core kicks ass. We’ll call him Mike. Mike is quite a stubborn lad and doesn’t want to install all that Microsoft mumbo-jumbo on his machine, which is perfectly understandable. .NET SDK and Visual Studio can take time and disk space to install and Mike doesn’t want that. But, Mike has heard how awesome Docker is and he even installed it at one time on his machine some time ago.

• -it: This command is actually comprised of two parts, -i which means interactive mode, and -t which enables the pseudo-terminal. These commands can be used separately to get the same result, but they are usually used together. The -it command basically gives us the means to see and interact with our application through the terminal.

• -p: Maps the external port (left) to the internal port (right) of the Docker container. In our case, this means that we can access our application through the http://localhost:8080 on our local machine, although it runs on a port 5000 inside the Docker container

• -v ${PWD}:/home/app: This one is a bit tricky but once you get it, it can do wonders. What this actually means is that it maps our current directory to the /home/app directory inside the container. This enables us to change the code on our local system and build it in the container. You can learn more about Docker volumes here.

Since Mike is a web developer in heart, he wants to make a small ASP.NET Core application to learn how web programming works in .NET Core. By some sheer luck, he stumbled across the Code Maze blog and found out that there is a great tutorial on how to create ASP.NET Core app and how to prepare it for dockerization. Just what he needs.

He can, of course, build his application on some of the many available CI/CD tools, and then deploy the application on the staging machine. Or he can publish directly using the Visual Studio publish tools. And he needs to do that both for Windows and Linux.