Im在我的本地機器上部署Docker容器。他們檢查他們是否成功部署的方式是通過瀏覽器並輸入http://192.168.99.105:7474/browser
。我想以編程方式做到這一點,所以我跟着Check if a url is reachable - Help in optimizing a Class這個問題的代碼。但是,當我嘗試它時,我得到System.Net.WebException {"The remote server returned an error: (504) Gateway Timeout."}
。如何檢查本地URL是否可達
它工作正常,但我也得到一個HttpStatusCode.OK
如果URL是https://en.wikipedia.org/wiki/YouTube
這是我的代碼:
private bool UrlIsReachable(string url)
{
//https://en.wikipedia.org/wiki/YouTube
HttpWebRequest request = WebRequest.Create("http://192.168.99.105:7474/browser") as HttpWebRequest;
request.Timeout = 600000;//set to 10 minutes, includes time for downloading the image
request.Method = "HEAD";
try
{
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
return response.StatusCode == HttpStatusCode.OK;
}
}
catch (WebException)
{
return false;
}
}
編輯:我的碼頭工人,compose.yml文件
version: '2'
services:
company1:
image: neo4j
ports:
- "7474:7474"
- "7687:7687"
volumes:
- $HOME/company1/data:/data
- $HOME/company1/plugins:/plugins
company2:
image: neo4j
ports:
- "7475:7474"
- "7688:7687"
volumes:
- $HOME/company2/data:/data
- $HOME/company2/plugins:/plugins
你有某種代理設置嗎? – lordkain
你如何開始你的Docker容器?請給出命令或docker-compose文件。 192地址是主機的本地網絡地址,還是運行Docker的虛擬機的地址? –
@lordkain不,我沒有,但我認爲這是'TCP'而不是'HTTP'。我在網站'web-sniffer.net'上試了一下,它給了我'只允許端口80,443,8080.'我的端口是7474. – jmc