CentOS deploys the. netcore application using Nginx + Docker, and centosng.pdf

Source: Internet
Author: User

CentOS deploys the. netcore application using Nginx + Docker, and centosng.pdf

Install docker official documentation https://docs.docker.com/engine/installation/linux/docker-ce/centos/

[root@sn ~]# Yum remove docker \ # delete old version

Docker-common \

Docker-selinux \

Docker-engine

 [root@sn ~]# yum install -Y yum-utils \

  device-mapper-persistent-data \
  lvm2
 [root@sn ~]#  yum-config-manager \
    --add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
 
[root@sn ~]# yum install docker-ce   #Installdocker
[root@sn ~]# systemctl start docker  #Startdocker

dockerRunhello-worldVerify that the image is correctly installed.

[root@sn ~]# docker run hello-world

 

Configure image Acceleration

 

 

[root@sn ~]# curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://3e722983.m.daocloud.io
[root@sn ~]# systemctl restart docker

 

 

Pull microsoft/dotnet Images

[root@sn ~]# docker pull microsoft/dotnet
[root@sn ~]# docker pull microsoft/microsoft/aspnetcore
[root@sn ~]# docker images

 

//StartdotnetImages
[root@sn ~]# docker run -it microsoft/dotnet 
//Create a project namedHelloDocker.WebOf.NET Core MVCProject
[root@sn ~]# dotnet new mvc -n HelloDocker.Web 
//EnterHelloDocker.WebFolder
[root@sn ~]# cd HelloDocker.Web 
//Start.NET Core MVCProject
 dotnet run

 

 

 

Mount a host project to a container

Upload the project's host demo directory through FileZilla:

 

 

Based on the microsoft/dotnet: latest image, map port 5000 to the host machine port 5000 and mount the host machine demo to the container app directory.

[root@sn ~]# docker run -p 5000:5000 -it -d -v /demo:/app microsoft/dotnet:latest
 
[root@sn ~]# docker ps

 

 

 

[root@sn ~]# docker exec –ti 4044ea20a695 /bin/bath 
root@630623fd1c84:/app/demo/SN_ITProjectSolution/WA_SNWeb# dotnet run

 

 

Test Results

The IP address 192.168.30.190: 5000 of the external access host automatically jumps to the Docker container 172.17.0.2: 5000, indicating that the deployment is successful.

 

Jump to port 5000 through Nginx Server Load balancer port 80

Install nginx: http://blog.csdn.net/Jenson_/article/details/77896608

Modify the configuration file: vi/usr/local/nginx/conf/nginx. conf

Modify and add code:

http {
    include       mime.types;
    default_type  application/octet-stream;
 
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
 
    #access_log  logs/access.log  main;
 
    sendfile        on;
    #tcp_nopush     on;
 
    #keepalive_timeout  0;
    keepalive_timeout  65;
 
    #gzip  on;
     upstream 192.168.30.190 {
     server 192.168.30.190:5000 ;
 }
    server {
        listen       80;
        server_name  192.168.30.190;
 
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
 
        location / {
            root   html;
            index  index.html index.htm;
            proxy_pass http://192.168.30.190;
        }

 

 

Test results:

 

External access to 192.168.30.190 (default port 80) jumps to 192.168.30.190: 5000, 192.168.30.190: 5000 is the ing port of the Docker container 172.17.0.2: 5000.

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.