1、获取microsoft/dotnet镜像
docker pull registry.cn-hangzhou.aliyuncs.com/cjx/tutorial
如果有问题确认已经使用阿里云镜像加速,参考:
http://www.cnblogs.com/windchen/p/6231009.html
如果不想使用此镜像也可以参照这篇直接从微软官方的镜像开始,如果是这样直接跳过第2步:
http://www.cnblogs.com/windchen/p/6235406.html
2、启动Web
docker run -itd -p 5000:5000 --name web registry.cn-hangzhou.aliyuncs.com/cjx/tutorial
3、获取nginx镜像
docker pull nginx
启动试试看是否正常:
docker run --name proxy -d -p 8080:80 nginxcurl -i http://localhost:8080docker rm -f proxy
4、配置nginx代理
先查看web容器的ip地址:
docker inspect web
"Networks": { "bridge": { "IPAMConfig": null, "Links": null, "Aliases": null, "NetworkID": "2e55cf78a8098776ab83b9d6b8002238ac6e843e736e3dd60e1de2a0eeb49cc5", "EndpointID": "909830fdfece4a1cdba9330be9a7c6b41f6c5ffd4e8687b19b70e2fd7bd365d4", "Gateway": "172.17.0.1", "IPAddress": "172.17.0.2", "IPPrefixLen": 16, "IPv6Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "MacAddress": "02:42:ac:11:00:02" } }
建立文件:my.nginx.conf,输入:
server { listen 80; location /{ proxy_pass http://172.17.0.2:5000; } }
重新启动nginx镜像,并把配置文件加载:
docker run --name proxy -d -p 8080:80 -v my.nginx.conf:/etc/nginx/conf.d/default.conf nginx
再访问http://localhost:8080,nginx已经将请求转发给web
时间: 2024-10-17 00:21:28