提问人:Boni García 提问时间:10/27/2023 最后编辑:Boni García 更新时间:10/31/2023 访问量:85
在 GitHub Actions 的 Docker 中使用主机网络时出现“连接被拒绝”
"Connection refused" when using host network in Docker in GitHub Actions
问:
我正在启动一个包含 Chrome 的 Docker 容器,如下所示:
docker run --rm --cap-add=SYS_ADMIN --network=host selenoid/vnc:chrome_117.0
在我的本地计算机中,此容器侦听以下 URL 中的传入请求:http://localhost:4444/
尽管如此,在 GitHub Actions 中启动该图像(使用主机网络)后尝试连接该 URL (http://localhost:4444/) 时,我遇到了“连接被拒绝”错误。我在Java中得到的错误如下:
Caused by: java.net.ConnectException: Connection refused (Connection refused)
我可以在 GitHub Actions 中使用主机网络吗?
答:
0赞
Arun Duraisamy
10/27/2023
#1
请看一下这个链接 如何从 docker containe 访问主机端口 和 Can't curl to localhost
尝试 http://host.docker.internal:4444/ 而不是localhost。
0赞
Boni García
10/31/2023
#2
我确认这可以在 GH Actions 中完成。我遇到的问题是使用 Xvfb。出于某种原因,使用 Xvfb 不允许我们在同一会话中使用端口 4444。
解决方法如下:
- 测试:https://github.com/bonigarcia/selenium-examples/blob/main/src/test/java/io/github/bonigarcia/selenium/remote/DockerWdmChromeCdpTest.java
- 工作流程:https://github.com/bonigarcia/selenium-examples/blob/main/.github/workflows/docker-java.yml
- 执行:https://github.com/bonigarcia/selenium-examples/actions/runs/6706576135
评论