主機 192.168.99.100 下面安裝 docker,并且已經部署好站點在容器內
(容器名稱 netcore_helloworld ,容器IP 172.17.0.12 可以通過 192.168.99.100:8066 訪問 )
創建一個Nginx組態檔 helloworld.conf
server {
listen 801; #監聽801埠
location / {
proxy_pass http://netcore_helloworld:80; #這里轉發沒有使用IP,使用 容器名稱:埠
}
}
自定義Nginx鏡像的Dockerfile
#定義基礎鏡像 nginx:latest
FROM nginx
#復制自定義的組態檔到Nginx組態檔目錄下
COPY helloworld.conf /etc/nginx/conf.d/helloworld.conf
#暴露80埠到外部
EXPOSE 80
#容器運行引數
CMD ["nginx", "-g", "daemon off;"]
制作鏡像 為 anginx
docker run --name mynginx -d -p 801:801 -p 80:80 anginx
失敗后查看日志
Docker logs 提示
host not found in upstream "netcore_helloworld" in /etc/nginx/conf.d/helloworld.conf:4
找了好多資料
helloworld.conf 修改如下代碼
upstream webapi {
#server www.google.com weight=10;
#server www.badi.com weight=3;
server netcore_helloworld:80 weight=5;
server 172.17.0.12:80 weight=5;
}
server {
listen 801; #監聽801埠
location / {
proxy_pass http://netcore_helloworld; #這里轉發沒有使用IP,使用 容器名稱:埠
}
}
容器可以啟動了,但 自定義Nginx鏡像 并未實作代理
那么正確方法應該怎么做?
========================================================
我的目的是 在 Docker 上有一個自定義 Nginx 鏡像,并且有單獨組態檔 helloworld.conf ,
該 Nginx容器 能和 其他web容器互相通信并實作代理
現在是 web容器都正常訪問 (宿主機IP 或者 容器IP 均可),現在如何通過 自定義的Nginx 去訪問?
如果那個 helloworld.conf 中寫死某個 IP或域名測驗是沒問題,但現在想用 容器:埠 是否可以實作?
uj5u.com熱心網友回復:

找到很多文章都說可以 容器:埠 結果都失敗 了
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/183330.html
標籤:Docker