问题的快速描述是:
app
和test
test
内获取chrome head,以获取公共网址test
成功加入app
test
加载在docker-compose网络上的chrome in head headless 我有一个包含两个服务的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
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
入口点脚本如下所示:
#!/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/
输出如下:
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>
因此,如果curl工作,并且chrome headless工作,为什么chrome无头加载http://app:5000
URL?
这是一个显示问题的完整回购:https://github.com/zilkey/docker-compose-chrome-headless-error
注意1:libudev: udev_has_devtmpfs: name_to_handle_at on /dev: Operation not permitted
可能是相关的,我可以解决一些方法,例如cap添加sys_admin,但它似乎没有任何影响。
注意2:关于ERROR:ssl_client_socket_impl
,应用程序不会公开SSL,所以这是预期的(我认为)。
答案 0 :(得分:1)
我无法准确地说出为什么,但将服务名称从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
显然,Chrome(至少按我设置的方式)处理http://app:5000/
的方式与http://other:5000
不同。