我们正在尝试在 docker 容器中运行 chrome。
构建后的docker run命令如下:
docker run \
--rm \
-ti \
--add-host=example.my_domain.localhost:172.21.0.13 \
--env="APP_ENV=test" \
--privileged \
--volume "$volumeDir:/app" \
--cap-add SYS_ADMIN \
--net custom_network \
built_image_tag bash
172.21.0.13是指示同一网络中另一个容器的 ip 的示例。
进入容器后,主机文件看起来像这样:
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.21.0.13 example.my_domain.localhost
172.21.0.15 7229a8eac11e
并按预期运行:
$ wget example.my_domain.localhost
Connecting to example.my_domain.localhost (example.my_domain.localhost)|172.21.0.13|:80... connected.
导致正确的连接
但是,在浏览器中运行连接:
$ google-chrome http://example.my_domain.localhost
导致ERR_CONNECTION_REFUSED。
浏览器能够导航到任何其他网站。
谢谢。
编辑: 请注意,wget和浏览器的打开都是在容器内启动的,因为我们使用 chrome headless 进行测试。