在我的虛擬機中,我有以下docker-compose.yml檔案:
services:
nginx:
image: "nginx:1.23.1-alpine"
container_name: parse-nginx
ports:
- "80:80"
mongo-0:
image: "mongo:5.0.6"
container_name: parse-mongo-0
volumes:
- ./mongo-0/data:/data/db
- ./mongo-0/config:/data/config
server-0:
image: "parseplatform/parse-server:5.2.4"
container_name: parse-server-0
ports:
- "1337:1337"
volumes:
- ./server-0/config-vol/configuration.json:/parse-server/config/configuration.json
command: "/parse-server/config/configuration.json"
指定的configuration.json檔案server-0如下:
{
"appId": "APPLICATION_ID_00",
"masterKey": "MASTER_KEY_00",
"readOnlyMasterKey": "only",
"databaseURI": "mongodb://mongo-0/test"
}
使用后docker compose up,我從 VM 執行以下命令:
curl -X POST -H "X-Parse-Application-Id: APPLICATION_ID_00" -H "Content-Type: application/json" -d '{"score":1000,"playerName":"Sean Plott","cheatMode":false}' http://localhost:1337/parse/classes/GameScore
輸出是:
{"objectId":"yeHHiu01IV","createdAt":"2022-08-25T02:36:06.054Z"}
我使用以下命令進入nginx容器:
docker exec -it parse-nginx sh
Pingingparse-server-0表明它確實決議為正確的 IP 地址。然后,我使用該主機名運行上述curl命令的修改版本:localhost
curl -X POST -H "X-Parse-Application-Id: APPLICATION_ID_00" -H "Content-Type: application/json" -d '{"score":1000,"playerName":"Sean Plott","cheatMode":false}' http://parse-server-0:1337/parse/classes/GameScore
它給了我這樣的 504 錯誤:
...
<title>504 DNS look up failed</title>
</head>
<body><div >
<div ></div>
<h1>504 DNS look up failed</h1>
<p>The webserver reported that an error occurred while trying to access the website. Please return to the previous page.</p>
...
但是,如果我no_proxy按如下方式使用,它可以作業:
no_proxy="parse-server-0" curl -X POST -H "X-Parse-Application-Id: APPLICATION_ID_00" -H "X-Parse-Master-Key: MASTER_KEY_00" -H "Content-Type: application/json" -d '{"score":1000,"playerName":"Sean Plott","cheatMode":false}' http://parse-server-0:1337/parse/classes/GameScore
輸出又是這樣的:
{"objectId":"ICTZrQQ305","createdAt":"2022-08-25T02:18:11.565Z"}
我對此感到非常困惑。顯然,parse-server-0可以通過 ping 訪問。它怎么能在不使用的情況下引發 504 錯誤no_proxy?parse-nginx容器使用默認設定和配置。我沒有設定任何代理。我正在使用它來測驗curl從另一個容器到parse-mongo-0. 任何幫助將不勝感激。
的內容/etc/resolv.conf是:
nameserver 127.0.0.11
options edns0 trust-ad ndots:0
echo $HTTP_PROXY在內部運行parse-nginx回傳:
http://10.10.10.10:8080
此值在 VM 內為空。
uj5u.com熱心網友回復:
您的代理服務器似乎沒有在此 docker 網路中運行。因此,當請求到達該代理服務器時,它不會查詢該網路上的 docker DNS 來決議其他容器名稱。
如果您的應用程式沒有在 docker 網路之外發出請求,您可以洗掉代理設定。否則,您需要no_proxy為將要訪問的其他 docker 容器進行設定。
uj5u.com熱心網友回復:
請檢查 的值echo $http_proxy。請注意這里的小寫字母。如果設定了這個值,這意味著 curl 被配置為使用代理。您得到 504 而 DNS 決議很可能是因為您的parse-nginx容器無法訪問 ip 10.10.10.10。并指定no_proxy告訴它忽略 http_proxy env var(覆寫它)并在沒有任何代理的情況下發出請求。
uj5u.com熱心網友回復:
在我的虛擬機中,這是~/.docker/config.json檔案的內容:
{
"proxies":
{
"default":
{
"httpProxy": "http://10.10.10.10:8080",
"httpsProxy": "http://10.10.10.10:8080"
}
}
}
這是不久前作為某些網路問題的臨時修復程式實施的。后來實施了安全證書。我完全忘記了修復。清除~/.docker/config.json檔案并重docker compose up做可解決問題。我不再需要no_proxy創作curl作品。一切都是現在應該的樣子。非常感謝您提供的所有幫助。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/505193.html
