. NET core MicroServices ASP.

Source: Internet
Author: User
Tags dotnet docker run

Tip: This article has been added to the. NET Core MicroServices Foundation Series index

First, the Docker minimalist introduction 1.1 General Introduction

Docker is an open source application container engine that is open source based on the Go language and complies with the APACHE2.0 protocol. Docker allows developers to package their apps and dependencies into a lightweight, portable container that can be published on any popular Linux machine or virtualized. Containers are completely sandbox-aware, there will be no interface between them (IPhone-like apps), and more importantly, the container's performance overhead is extremely low.

In a nutshell > container is a packaged application service environment, it is a lightweight virtual machine , each container consists of a specific set of applications and the necessary dependent libraries.

The biggest difference between Docker and traditional virtualization is that containers are virtualized at the operating system level, which is the direct reuse of the local host's operating system , while traditional virtualization is implemented at the hardware level, such as VMware Vshpere, Xen, and Citrix.

1.2 Docker structure

Docker uses the client-server (c/s) architecture pattern to manage and create Docker containers using remote APIs.

Docker containers are created with Docker images.

A container's relationship to mirroring is similar to objects and classes in object-oriented programming .

As shown in the Docker architecture, the Client communicates with the server process through the interface to build, run, and publish the container. The client and server can be run in the same cluster, or remote communication can be implemented across hosts.

For details, please visit: "A few diagrams to help you understand Docker fundamentals and QuickStart"

Second, the installation of Docker

(1) Prepare a Linux host with CentOS 7.2 as an example. Of course, you can also use Windows, but you have to make sure that the Windows Pro version and above are installed with a series of related software such as Hyper-V.

(2) Installing Docker

# Yum Install Docker

  

(3) Start Docker service

# Systemctl Start Docker.sevice

  

(4) Configure boot-up and verify

# Systemctl Enable Docker.service

  

Verify: View Docker version information

# Docker version

  

(5) Configuring the Docker accelerator = cause you know, not set to slow you down, except for cloud servers

# Vim/etc/docker/daemon.json

{

"Registry-mirrors": ["https://d8b3zdiw.mirror.aliyuncs.com"]

}

Then restart the Docker service

# Systemctl Daemon-reload

# Systemctl Restart Docker

(6) Hello World

# Docker Run Hello-world

  

Iii. ASP. NET Core on Docker configuration

(1) Pull up the latest image of Dotnet/aspnetcore, here take Aspnetcore 2.0 as an example

# Docker Pull microsoft/aspnetcore:2.0

  

PS: If you want to pull the latest version (for example,. NET Core 2.1), you can change the version number to Aspnetcore:latest

  If you want to pull more images from Microsoft, then search for: # Docker Search Microsoft

  

Pull out the unwanted image, then delete one, like: # Docker RMI Imagesid

  

After the pull, verify that the pull is successful: # Docker images

  

(2) Now we go into vs and edit a dockerfile for one of our ASP. NET Core Webapi

# Parent Image from Microsoft/aspnetcore:2.0# set working directory Workdir/app# Copy the Publish file to/app copy below./app# Setting the port expose8810# Use dotnet Manulife.DNC.MSAD.NB.AgentService.dll to run the ASP. NET core project, note case EntryPoint ["dotnet","Manulife.CD.MSAD.NB.AgentService.dll","--server.urls","http://*:8810"]

(3) Publish this ASP. NET Core WebAPI and transfer the release file to the Linux server (you can choose tools such as XFTP or WINSCP)

  

(4) Enter the Agentservice directory and start packing the Docker image

# docker Build-t agentservice-container:1.0. = Don't forget that there is another point behind.

  

Now again verify: # Docker images

  

(5) Long March last step: Run Docker

# docker Run-name agentservice-d-P 8810:8810 agentservice-container:1.0

  

The two port numbers here are the host and container mappings, the previous one is the port number you are accessing externally, and the next is the port number you want to map to the Docker container, keeping in mind that the port number we exposed in the dockerfile is consistent.

  PS: here if the Docker run fails again after the prompt name already exists, you can use the following command to delete the container

# docker Rm-f [Dockername]

If you want the Docker container to restart automatically after an abnormal exit, you can add the--restart option, for example:

# Docker Run--name agentservice-d-P 8810:8810 agentservice-container:1.0--restart=always

(6) Verify Docker run effect

Method One: In the host authentication

  

Mode two: Accessing the remote client through the browser

  

Four, supervisor Guardian process

  

This section is primarily for dotnet core applications on Linux, which ensures that the program will still be able to access it when the exception or the computer restarts. You can browse Yang Xiaodong's "ASP. NET core Linux to create daemons for dotnet" and Focus-lei's "running on Docker" to learn, here is not to repeat.

Resources

(1) Beginner's tutorial, "Docker Tutorial"

(2) Yang Xiaodong, "ASP. NET core Docker Deployment", "Creating Daemons for Dotnet under ASP."

(3) Li Chaoqiang, "Docker packaged ASP. NET core application, running on CentOS"

(4) Shengjie, ". NET Core containerized @docker"

(5) Focus-lei, "running the. NET core program on Docker"

Zhou Xurong

Source: http://edisonchou.cnblogs.com

The copyright of this article is owned by the author and the blog Park, welcome reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to give the original link.

. NET core MicroServices ASP.

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.