Docker部署Nginx和.NetCoreMVC笔记
2019-04-21 本文已影响0人
GH_12d8
1. 测试 Docker部署Nginx
#拉取nginx镜像
docker pull nginx
#运行nginx容器将宿主机5000端口映射到容器的80端口
docker run -d -p 5000:80 --name HiNginx nginx
cur http://localhost:5000
#测试完成,删除 a739是container id
docker stop a739
docker rm a739
2. 启动.Net Core Docker
Docker中部署.Net Core MVC笔记
https://www.jianshu.com/p/cb48572e3c6e
#4e36 是firstmvc 的container id
docker start 4e36
3. 配置Nginx反向代理
#查询firstmvc容器的IP地址
docker inspect firstmvc | grep IPAddress
"SecondaryIPAddresses": null,
"IPAddress": "172.17.0.3",
"IPAddress": "172.17.0.3",
cd ~
mkdir nginx
cd nginx
touch first_nginx.conf
vi first_nginx.conf
first_nginx.conf
server {
listen 5000;
location / {
proxy_pass http://172.17.0.3;
}
}
4. 启动Nginx
#启动Nginx容器并通过挂载的方式将配置文件共享到容器内部
#Nginx配置反向代理的配置文件路径为:/etc/nginx/conf.d/default.conf
docker run -d -p 5000:80 -v $HOME/nginx/first_nginx.conf:/etc/nginx/conf.d/default.conf nginx
#测试
curl http://localhost:5000
5. 集群部署,均衡负载
cd ~/nginx
vi first_nginx.conf
#test 自定义名称
upstream test {
ip_hash;
server 172.17.0.2:80 weight=10;
server 172.17.0.3:80 weight=20;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://test;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
6. MySql Docker
docker pull mysql:5.7.25
docker run --name first-mysql -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 -d mysql