1. 安裝docker;php
2. vs2017 建立asp.net core項目,並添加docker支持;html
3. docker-compose build 建立docker鏡像;nginx
4. docker run -d -p 5001:80 --name dockerdemo.web1 dockerdemo 建立容器(多個);web
5. docker ps 查看建立的容器;docker
6. docker inspect 查看容器信息,ip地址;瀏覽器
7. docker pull nginx 下載nginx鏡像app
docker run -d -p 8080:80 E:\SampleCode\DockerDemo\nginx\nginx.conf:/etc/nginx/nginx.conf nginx 啓動一個新的Nginx容器並經過掛載的方式將配置文件共享到容器內部(nginx.conf)asp.net
8. 編輯本地nginx.conftcp
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/名稱;ui
10. 瀏覽器中訪問 http://localhost:8080/