In this paper, by deploying .NET Core micro-service architecture developed by Docker, including micro-services deployment Unified Gateway (using Ocelot development), unified authentication (IdentityServer4), application services (ASP.NET Core WebAPI).
This article does not carry out instructions for micro-services, follow-up will be against my understanding of the micro-services in record keeping.
A, Docker principle ¶
The easiest to Docker and awareness with a certain error is "Docker is a very good performance in a virtual machine."
But this is certainly wrong to say. Docker compared to traditional virtual machine technology is advanced a lot, in particular in Docker is not a set of virtual hardware on the host and then a virtual operating system, but to Docker container inside the process run directly in places on the host (Docker will do quarantined files, networks, etc.), so that Docker will be "lighter volume, run faster, the number of under the same host can create more."
-
Docker There are three core concepts: Image, Container, Repository.
-
Image: We are no strangers to the concept of mirroring. But the kind of windows and compared to iso image, Docker in the mirror is hierarchical, reusable, rather than a simple pile of papers stacked together (similar to a difference of source package git repository and a compression) .
-
Container: the presence of the container without the support of the mirror, he was a carrier (similar to the relationship instance and class) mirror runtime. Relying on Docker's virtualization technology, to create an independent container ports, processes, files, and other "space", Container isolation is a "container" and the destination host. The container may be in communication port, volumes, network between the host and the like.
Repository: git warehouse and warehouse Docker quite similar, with the repository name, tag. After the local mirror finished building, to be distributed by mirroring warehouse.
Docker hub commonly used are:
https://hub.docker.com/(docker official)
https://cr.console.aliyun.com/
Two, Windows system Docker installation ¶
1, Enable Hyper-V¶
Open the Control Panel - Programs and Features - Enable or disable Windows features, check the Hyper-V, and then click OK to as:
2. Download and install Docker¶
Download: https: //hub.docker.com/editions/community/docker-ce-desktop-windows, need to register an account to download Docker
Once downloaded directly installed
View Docker version command:
3, the mirror address modification ¶
Since Docker official mirror will be very slow, I modified Ali cloud mirror
4, the test ¶
Almighty HelloWorld, run hello-world PowerShell run by Docker
docker ps -a // check the running container
Above is the whole process of Windows installed Docker environment
Third, install Docker environment ¶
I was in the AWS application with a free server, ubuntu system is used. If you need to apply for AWS servers, AWS can apply through the official website registered account, you need to fill out a credit card account, https: //portal.aws.amazon.com/billing/signup#/start
This article ubuntu install Docker is a direct reference to the official tutorial: https: //docs.docker.com/install/linux/docker-ce/ubuntu/
When the installation is preferably installed to switch to the root account
ubuntu remote through putty, specifically how you can use Baidu
Fourth, release and deployment services ¶
1, create Dockerfile, publishing the application ¶
This is my project directory, image is constructed by Dockerfile to build.
VS2017 supports automated build Dockerfile file, right-engineering - Add -Docker support
Here are the contents of my Dockerfile:
The FROM in the Microsoft / aspnetcore : 2.1 // base image here is the core of the operating environment foundation .net WORKDIR / publish // Create a project directory COPY . / Publish // current directory will be copied to the mirror, pay attention COPY followed by another space. EXPOSE 80 // Foreign exposed container port 80 EntryPoint [ "DOTNET" , "ZY.Gateway.dll" ] // start the service in the container // here to build the equivalent of a mirror command is executed line by line
Dockerfile need to set the compiler output to publish directories
After the above are set up, the publisher by VS
After successfully posted, find the file after we released under the bin / release directory project directory
Other publishing services similar with the above release
2, upload it to the ubuntu ¶
By WinScp upload tool, the three services are uploaded to the server, WinScp how to use, you can look at Baidu
3, the mirror constructed ¶
Docker Build - T apigateway . // build gateways mirror Docker Build - T identityserver - F / Home / Ubuntu / dockerapp / identityserver / publish / Dockerfile . // Construction authentication service mirror Docker Build - T TestServer - F / Home / Ubuntu / dockerapp / testserver / publish / Dockerfile .// build testing services Mirror - t // image name - f // dockerfile file path
docker images // View Mirror
4, run container ¶
Mirror has been completed in front of the building, this step would be to run the container constructed in accordance with the mirror, our service up and running
Docker RUN - d - the p- 5000 : 80 - name apigateway_container apigateway Docker RUN - d - the p- 6000 : 80 - name identityserver_container identityserver Docker RUN - d - the p- 7000 : 80 - name testserver_container testserver // respectively gateway services, Certification services, testing services container run up // - d keep the background processes running -p port mapping, port {host}: {} container port
Check the operation of container docker ps -a command
When configuring the gateway service will involve network access between the container and the container, Docker will create a gateway IP 172.17.0.1 at the time of installation, you can do port forwarding 172.17.0.1.
You can view docker0 gateway command
Api gateway routing forwarding configuration
5, call the service ¶
Postman by calling a service run by Docker, get through the API Gateway Access Token Authentication Service
to sum up¶
Docker entire installation, service releases, packaged mirror, run the container to complete.
The whole process is not coherent, I stepped on a lot of the pit, and also learned a lot in understanding the process of stepping in the pit.