[英]Chrome headless can't access URL on network in docker-compose
The quick description of the problem is: 问题的快速描述是:
app
and test
app
和test
test
to reach public URLs test
让chrome没头没脑地访问公共URL test
to successfully curl to app
test
以成功卷曲到app
test
to load URLs that on the docker-compose network in chrome headless test
将docker-compose网络上的URL加载到chrome headless中 I have a docker-compose file with two services like so: 我有一个包含两个服务的docker-compose文件,如下所示:
version: '3'
services:
app:
build:
context: .
dockerfile: App.Dockerfile
ports:
- 5000:5000
restart: always
test:
build:
context: .
dockerfile: Chrome.Dockerfile
depends_on:
- app
The Chrome.Dockerfile
installs chrome like so: Chrome.Dockerfile
会Chrome.Dockerfile
安装chrome:
FROM node:8-slim
RUN apt-get update --fix-missing && apt-get -y upgrade
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
&& apt-get install -y google-chrome-unstable --no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /src/*.deb
ADD entrypoint .
CMD ./entrypoint
And the entrypoint script looks like this: 入口点脚本如下所示:
#!/bin/bash
echo ""
echo "Demonstrates that curl can access the host app on port 5000..."
echo ""
curl http://app:5000/
echo ""
echo "Demonstrates that chrome headless is working..."
echo ""
google-chrome \
--headless \
--disable-gpu \
--no-sandbox \
--dump-dom \
http://example.com/
echo ""
echo "Demonstrates that chrome headless is not successful with app:500"
echo
google-chrome \
--headless \
--disable-gpu \
--no-sandbox \
--dump-dom \
--enable-logging --v=10000 \
http://app:5000/
The output looks like this: 输出看起来像这样:
Starting experiment_app_1 ... done
Demonstrates that curl can access the host app on port 5000...
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>A page</title>
</head>
<body>
<h1>A heading</h1>
</body>
</html>
Demonstrates that chrome headless is working...
[0303/074652.347092:ERROR:gpu_process_transport_factory.cc(1007)] Lost UI shared context.
libudev: udev_has_devtmpfs: name_to_handle_at on /dev: Operation not permitted
Fontconfig warning: "/etc/fonts/fonts.conf", line 146: blank doesn't take any effect anymore. please remove it from your fonts.conf
<!DOCTYPE html>
<html>
...all the html from example.com
</html>
Demonstrates that chrome headless is not successful with app:5000
[0303/074652.598662:VERBOSE1:zygote_main_linux.cc(336)] ZygoteMain: initializing 0 fork delegates
[0303/074652.599327:INFO:cpu_info.cc(50)] Available number of cores: 4
[0303/074652.603129:ERROR:gpu_process_transport_factory.cc(1007)] Lost UI shared context.
[0303/074652.603580:VERBOSE1:pulse_stubs.cc(683)] dlopen(libpulse.so.0) failed, dlerror() says:
libpulse.so.0: cannot open shared object file: No such file or directory
[0303/074652.603681:VERBOSE1:pulse_util.cc(106)] Failed on loading the Pulse library and symbols
[0303/074652.603843:VERBOSE1:webrtc_internals.cc(114)] Could not get the download directory.
libudev: udev_has_devtmpfs: name_to_handle_at on /dev: Operation not permitted
[0303/074652.609098:VERBOSE1:breakpad_linux.cc(1997)] Non Browser crash dumping enabled for: renderer
Fontconfig warning: "/etc/fonts/fonts.conf", line 146: blank doesn't take any effect anymore. please remove it from your fonts.conf
[0303/074652.708611:VERBOSE1:multi_log_ct_verifier.cc(75)] Adding CT log: Google 'Aviator' log
...more logs
[0303/074652.708843:VERBOSE1:multi_log_ct_verifier.cc(75)] Adding CT log: Certly.IO log
[0303/074652.708853:VERBOSE1:proxy_service.cc(955)] PAC support disabled because there is no system implementation
[0303/074652.713231:VERBOSE1:network_delegate.cc(30)] NetworkDelegate::NotifyBeforeURLRequest: http://app:5000/
[0303/074652.715447:VERBOSE1:network_delegate.cc(30)] NetworkDelegate::NotifyBeforeURLRequest: https://app:5000/
[0303/074652.719183:ERROR:ssl_client_socket_impl.cc(1098)] handshake failed; returned -1, SSL error code 1, net_error -107
[0303/074652.738050:VERBOSE2:ThreadState.cpp(533)] [state:0x55a5e7840fc0] ScheduleGCIfNeeded
...
[0303/074652.742949:VERBOSE1:V8ContextSnapshot.cpp(140)] A context is created from snapshot for main world
[0303/074652.746847:VERBOSE2:ThreadState.cpp(496)] [state:0x55a5e7840fc0] SchedulePageNavigationGCIfNeeded: estimatedRemovalRatio=0.75
[0303/074652.749427:VERBOSE1:V8ContextSnapshot.cpp(140)] A context is created from snapshot for main world
[0303/074652.763112:VERBOSE1:sandbox_ipc_linux.cc(131)] SandboxIPCHandler stopping.
<html><head></head><body></body></html>
So if curl works, and chrome headless works, why can't chrome headless load the http://app:5000
URL? 因此,如果curl有效且chrome headless有效,为什么chrome headless无法加载
http://app:5000
URL?
Here's a complete repo that shows the problem: https://github.com/zilkey/docker-compose-chrome-headless-error 这是显示问题的完整仓库: https : //github.com/zilkey/docker-compose-chrome-headless-error
NOTE 1: The libudev: udev_has_devtmpfs: name_to_handle_at on /dev: Operation not permitted
could be related, and I can solve that a few ways such as cap add sys_admin but it doesn't seem to have any effect. 注意1:
libudev: udev_has_devtmpfs: name_to_handle_at on /dev: Operation not permitted
可能是相关的,我可以解决一些方法,例如cap add sys_admin,但这似乎没有任何效果。
NOTE 2: Regarding the ERROR:ssl_client_socket_impl
, the app doesn't expose SSL, so this is to be expected (I think). 注意2:关于
ERROR:ssl_client_socket_impl
,该应用程序未公开SSL,所以这是可以预期的(我认为)。
I can't tell exactly why yet, but changing the service name from app
to something other than app
fixes it: 我不能告诉到底为什么呢,但是从改变服务名称
app
比其他一些app
修复它:
version: '3' services: other: build: context: . dockerfile: App.Dockerfile ports: - 5000:5000 restart: always test: build: context: . dockerfile: Chrome.Dockerfile depends_on: - other
Apparently Chrome (at least the way I set it up) handles http://app:5000/
differently from http://other:5000
. 显然,Chrome(至少是我的设置方式)对
http://app:5000/
不同于http://other:5000
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.