我在本地机器上部署 docker 容器。我检查它们是否已成功部署的方法是转到我的浏览器并键入http://192.168.99.105:7474/browser
. 我想以编程方式执行此操作,因此我遵循了此问题Check if a url is reachable - Help in optimization a Class 中的代码。但是,当我尝试时,我得到一个System.Net.WebException {"The remote server returned an error: (504) Gateway Timeout."}
.
它工作正常,HttpStatusCode.OK
如果网址是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;
}
}
编辑:我的 docker-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