Docker4dotnet #1 – Past Life & World Hello

Source: Internet
Author: User
Tags docker for mac docker compose docker toolbox

As a. NET Developer, looking at the popularity of Docker over the years is a bit envious. Unfortunately, Docker is based on the Linux environment, the eyes look at those Java, Python, node. js, go even PHP programmers can Docker, and their own in the bitter haha installed virtual machine, it is urgent AH! So there's a special focus on the development of. NET core, because its cross-platform means that. NET developer can also be Docker.

Past Life

The. NET core 1.0 is not an upgrade to the original. NET platform, but rather a new rewrite, the development process that Microsoft has adopted as an unprecedented open-source approach, accepting pull request from global developers on GitHub. As you can see,. NET core is parallel to the existing. NET Framework and is a fully independent development platform. The biggest difference from the previous. NET Framework is the cross-platform support for the Windows/macos/linux three operating systems. On GitHub, the release timeline for. NET core can be seen over the past 2 years, Microsoft has stepped up the. NET from the Windows operating system and gradually added support for MacOS and Linux operating systems, while collaborating with the open source community is deepening.

– July 2014 – Microsoft released the predecessor of ASP. NET VNext (that is, ASP. NET 5) on GitHub, and this is the alpha phase
– November 2014-released Beta1, and started using the name of ASP. NET 5
– October 2015-released Beta8, this is the last beta release, this year, Microsoft has gradually provided support for MacOS and Linux operating systems, along with the popularity of the cross-platform code Editor for Visual Studio Code, Let's start focusing on ASP. 5
– November 2015-released RC1, marking the ability of the ASP. NET 5 to use the production environment
– June 27, 2016 – at the Redhat full stack Developer conference devnation, Microsoft and Redhat together published ASP. NET Core 1.0, marking the official release of Microsoft as a cross-platform development tool.

Why is Docker?

Let's take a look at Docker, a 2013-year-old open-source project that has attracted a great deal of attention from the world's developers from the start, with more than 50,000 downloads in 4 months of release, and more than 4,000 star on GitHub, with more than 100 contributors emerging, And there are more than 150 projects and more than 1000 products to start using Docker. Within 1 years, Redhat and AWS announced official support for Docker, and under such great concern, even Docker's own CEO persuaded developers around the world to temporarily not use Docker for production environments. In June 2014, Docker released the 1.0 version, when Docker downloaded more than 2.75 million, and today this number has exceeded 1 billion.

Why the small part of Docker so mouth-watering, this word from "repair computer". As a programmer, who has not repaired a computer, who has not been called to repair the computer, who is not considered to be very good at repairing the computer ... But, have you ever wondered why we are so good at repairing computers? Is it really because of the sister? That's a byproduct, all right?!!

Story...... One months ago took a project, using the XXX technology, set up a good environment, the one months of dry; Today, the project manager said there are other projects here are some small problems need to deal with, you come to see, not much time. As a result, you find that this project is using YYY technology, build the environment for your half a day, this time the project manager called: "Why is not finished?" What, the environment has not done well, forget, you do not engage, I find others! “。 All right, bitter force you go back to the original project, found that the variable XXX environment is yyy messed up, changed a long time also do not ... The result is: from! Mount Electric! Brain!

This is how programmers become the Master of the machine! Then the programmer began to use the virtual machine, the development environment into the virtual machine, so that there is no fear of conflict between different environments, but the virtual machine with dozens of g of hard disk occupancy and huge CPU and memory overhead to make the computer sluggish, originally i7 machine can only enjoy i3 performance, too wasted.

That's why Docker has become a global programmer's Gospel:

– Do not worry about the complexity of the newly inherited project environment;
– No need to worry about the simultaneous development of 2 conflicting environment projects;
– No more memory and hard drives, the environment starts quickly, it takes a few seconds to start a container, and a virtual machine takes a few minutes, and even 8G of memory can run multiple containers at the same time, while virtual functions run 2.
– Simply throw a good application to the test and test without having to re-build the environment yourself, to restore a clean test environment is just a command;
– Simply throw the tested application to OPS, without having to rip JDK 1.8 or 1.7 with OPS
– The environment is broken, change a new one, don't bother to look at log, restore the recovery that
– Don't worry that the programmer next to you uses a different version of the JDK, his environment is your environment, even if you use the laptop is Win7, he is on the tall MacBook Pro

Isn't this a programmer's paradise? That's what Docker brings to us, and that's why programmers are impatient to start using Docker and are willing to break through the drag to let Ops accept Docker, something that hasn't happened historically, and has always been a requirement for development using a standardized environment.

In fact, Docker solves a problem that has plagued every it person's environment ; This problem with the explosive growth of various technologies, frameworks and platforms eventually become the ultimate killer of application development efficiency, which makes developers and businesses pay great effort and money. Whether it's itsm at the organizational and process level, or devops from an agile perspective, or automation (such as chef/puppet, etc.), there is no whirlpool of this problem. These methods or tools try to use complex methods to adapt to the complex environment , and Docker is to use a reverse thinking approach to solve the problem, with a simple way to solve complex problems , it is a bit of the feeling of four or two!

Why it's called Docker: the Container Technology (Containers) used by Docker comes from the shipping industry's container (Containers) mentality. The transport industry encountered the same problem in the 60 's, and we wanted to ship all sorts of things in different sizes, which caused great inconvenience to the shipping process. This is as if we need to transfer different environments, different versions of applications from development to testing, and then to production.

So the container began to appear, the transport company will be different sizes of goods into a unified container, so whether it is truck, dock machinery, aircraft and ship cargo warehouses can be designed according to the standard container size, greatly improve the efficiency and reduce costs. Docker is here to serve this container, allowing developers to load environments and applications into containers as needed, while test and OPS personnel only need to be transported and loaded.

Docker borrowed the idea of container transportation, packaged all the environments needed for the application, and used lightweight virtualization technology to provide a relatively isolated run-time space on top of the operating system. In this way, developers can directly complete the packaging of the dependent environment and the application itself, while the test/OPS personnel only need to mount the operation.

Development environment Selection

To use Docker to develop a. NET core application, you can choose your preferred operating system and tools, in this series, I will describe the 2 most common development environments

– Windows + Visual Studio + Docker for Windows
–macos + Visual Studio Code + Docker for Mac

Deployment environment, I will use Microsoft Azure and Amazon AWS to deploy test and production environments, and implement the release pipeline from Dev-Test-production with visual Studio Team Service as a devops toolchain (release Pipeline) is established.

Docker World, Hello!

Today I'll take a look at the simplest scenario, building a Docker for Windows development environment on Windows 10 and using Visual Studio 2015 and the Docker for Visual Studio plug-in to complete the creation of a. NET Core app and debugging.

You can use this 5-minute video to learn the following effects, if you need to know the detailed steps, see the following instructions:

1. Install Docker for Windows on Windows

Docker for Windows is a development and test environment provided by Docker for developers who use Windows, formerly known as Docker Toolbox. The difference between Docker for Windows and Docker Toolbox is that the former uses Hyper-V for virtualization support, and Docker Toolbox uses VirtualBox. Therefore, if you are using the Windows 10 operating system, you can use Docker for Windows, and if you are using an older operating system, you can use Docker Toolbox.

You can download these 2 tools from the following address:

In this article I'm using Docker for Windows and Windows 10 environments, and Docker for Windows is also required for Windows 10, with the minimum required version 1511 (OS Build 10586 ), you can view your version information through the winver command.

The installation process is very simple, just double-click the downloaded installation package, the next step can be completed. In this process, if your machine is not enabled for Hyper-V, the installer is automatically enabled. If your Windows 10 is a virtual machine, depending on the virtualization tool you are using, you can start the virtualization nesting, which is to run the virtual machine inside the virtual machine.

After you install it, be sure to start Docker for Windows with administrator privileges, or Docker for Windows will not be able to communicate with the Hyper-V console, causing the environment to start failing.

A system notification pops up when Docker for Windows starts successfully.

You can also see a LINUXVM running in the Hyper-V console.

As you can see from the above process, Docker for Windows is actually running a virtual machine running Docker Daemon (stationed program) in Hyper-V. The Docker command-line tool running on Windows points to the Docker environment in this virtual machine. For developers, we only need to run CMD or PowerShell command line on Windows, and we can use the same Docker command.

2. Installing the Docker for Visual Studio plug-in

Visual Studio's powerful development and debugging capabilities help improve efficiency, and in order to provide a docker-based development and debugging experience, Microsoft provides a Docker Tools for Visual Studio plug-in.

If you have not yet installed Visual Studio 2015, you can download the latest Community Edition at the following address, which is completely free and also supports loading plugins.


When you are ready, open Tools | Extensions and Update menu, enter Docker to search, you can find this plugin:

Plug - ins:


3. Preparing the. NET Core Environment

First, go to the. NET core's Windows Environment home page and follow the requirements to download and install. NET Core 1.0 for Visual Studio, as follows

Once installed, you can create a. NET Core app in Visual Studio.

4. Create a. NET Core Web App in Visual Studio 2015

Click File | New | Project ..., open the item creation bootstrap, and select the ASP. NET Core WEB Application

Select the Web application template in the Templates page and click OK to create it

After the creation is complete, Visual Studio automatically runs the dotnet Restore command to restore the project dependencies, waits for the process to complete, and then presses F5 to test it, normally you can see the following initial site status.

5. Enable Docker support and use the Docker environment for debugging

Right-click on the project node and select Add | Docker Support

In this case, you will be given the following 2 parts of the project:

(1) This is where Visual Studio is configured to ensure that the tool chain of Visual Studio is properly integrated with the Docker environment
(2) Here is the configuration of Docker's own environment, including Dockerfile and Docker Compose file (which is described in the following article), plus a dockertask.ps1.

DOCKERTASK.PS1 is a PowerShell script, and the interaction between Visual Studio and Docker is actually done through this script, where the parameters section of the script is posted, and you see a layer of encapsulation of commonly used Docker commands in the script. Let Docker be a better match for Visual Studio's toolchain calls. This script is very useful, especially if you do not have Visual Studio, you can use this script to manually complete the tool chain build.

Now, you'll find that one more Docker option in the Run status bar of Visual studio means that we can simply click on this button or F5 to deploy the app to a local Docker for Windows environment and start debugging.

The effect of running is as follows

You can see that I added a line of code in the controller to get the local machine name, the container is the ID of the container, but also here can set breakpoints, the application running in Docker will be interrupted, You can debug this app running in Docker just like debugging a normal ASP.

This article is just the beginning of the Docker for. NET Developer (D4D) series , and you can see that with Visual Studio's consistent development and debugging capabilities and Docker's environmental isolation capabilities, development efficiencies can be greatly improved. The follow-up will also show you how to use Docker for development on MacOS, while supporting the completion of Docker environment integration in the cloud with VSTS's DevOps toolchain.

The tool used in this article some need to turn over the wall to normal download, small series will they tidy up a bit on the cloud disk, for everyone to download high-speed, the need for a friend please public attention to the public number Devopshub, and in the message input d4dtools get, thank you!

Please follow the public number "Devopshub" For more information on DevOps integration


Docker4dotnet #1 – Past Life & World Hello

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.