Before you look at the article, you need to know about Docker.
1. Create WebApp Application
I'm using. Net Core 1.0.1, creating an MVC application, and adding a reference to Redis. Because these are very basic, but also very simple, here is not detailed, specifically mention about the multi-site session retention problem, here are two ways, one way is to use the method of my blog said Http://www.cnblogs.com/anech/p/6873604.html, Another way is to use the Nginx proxy session-keeping scheme.
2. Create a webapp dockerfile file
From Microsoft/aspnetcore:1.0.1entrypoint ["dotnet", "TestCentOS.dll"]arg source=. ARG port=80env aspnetcore_urls http://+: $portWORKDIR/appexpose $portCOPY $source.
A new image is created using the microsoft/aspnetcore:1.0.1 base image, and the image is executed at run time dotnet The TestCentOS.dll command starts the program, copies the files in the current directory to the Mirror, and exposes a specified port if the default 80 port is not specified.
3. Create Nginx Dockerfile file
From Nginxexpose 80COPY default.conf/etc/nginx/conf.d/
The main idea is: Create a new image based on the Nginx base image, expose 80 ports externally, and copy the default.conf under the current directory to the mirrored/etc/nginx/conf.d/directory.
default.conf File Contents:
Upstream webapp{ server weba:80 max_fails=3 fail_timeout=20s; Server webb:80 max_fails=3 fail_timeout=20s; } server { listen default_server; Listen [::]:80 default_server; server_name _; Location/{Proxy_pass http://webapp/; Proxy_http_version 1.1; Proxy_set_header Upgrade $http _upgrade; Proxy_set_header Connection keep-alive; Proxy_set_header Host $host; Proxy_cache_bypass $http _upgrade; } Error_page 404/404.html; Location =/40x.html { } error_page 502 503 504/50x.html; Location =/50x.html { } }
Here is the load configuration for NIGNX, which configures the address of two applications.
4. Create a docker-compose.yml file
Version: ' 2 ' services: nginx: image:testnginx# build:# context:. # Dockerfile:nginxdockerfile ports: -"5000:80" Links: -Weba -Webb Weba: image:testweb# build:# Context:. # Dockerfile:dockerfile expose: -"page" Links: -Redis Webb: Image: testweb# build:# context:. # Dockerfile:dockerfile expose: -"About" Links: - Redis Redis: image:redis expose: -6379
For the sake of convenience, I first performed the Dockerfile file above to create a mirrored testweb and Nginx mirror Testnginx for a. NET core application, and then we used both mirrors when we created the cluster. This can also be omitted, created directly using Dockerfile, which creates three mirrors as we deploy two applications Weba and Webb applications and one nginx.
The main idea of this yml file is: Create and start 4 containers, an nginx container, two webapp containers, a redis container, Nginx exposed port 80 and the native 5000 port mapping, Nginx container can access two webapp containers, The Redis container is accessible to two webapp containers. This allows us to implement Nginx proxy requests and distribute them to back-end two webapp applications, and two WebApp applications using Redis services.
5. Execute docker-compose.yml File
The command is very powerful and will attempt to automate a series of operations including building the image, (re) creating the service, starting the service, and correlating the service-related container.
You can see the effect when you visit http://localhost:5000/.
Article Source: http://www.cnblogs.com/anech/p/6873828.html
Docker-compose Deploy ningx+.net Core+redis cluster with one click