1. 安装docker;

2. vs2017 创建asp.net core项目,并添加docker支持;

3. docker-compose build 创建docker镜像;

4. docker run -d -p 5001:80 --name dockerdemo.web1 dockerdemo 创建容器(多个);

5. docker ps 查看创建的容器;

6. docker inspect 查看容器信息,ip地址;

7. docker pull nginx 下载nginx镜像

    docker run -d -p 8080:80  E:\SampleCode\DockerDemo\nginx\nginx.conf:/etc/nginx/nginx.conf nginx  启动一个新的Nginx容器并通过挂载的方式将配置文件共享到容器内部(nginx.conf)

8. 编辑本地nginx.conf

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;
    upstream demo_server {  
        server 172.17.0.2;  #web1 ip
        server 172.17.0.3;  #web2 ip
    }

    #include /etc/nginx/conf.d/*.conf;
    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;
        #access_log  /var/log/nginx/host.access.log  main;

        location / {
            proxy_pass http://demo_server;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
}

9. 重启nginx容器  docker restart 容器id/名称;

10. 浏览器中访问 http://localhost:8080/

 posted on 2018-05-14 16:19  Wolfei  阅读(170)  评论(0编辑  收藏  举报