Chrome headless无法在docker-compose中访问网络上的URL

问题描述 投票:0回答:1

问题的快速描述是:

  • 我有两个服务的docker-compose设置:apptest
  • 我可以在test内获得chrome headless来访问公共URL
  • 我可以让test成功地卷曲到app
  • 但我无法让test加载在docker-compose网络上的无头网络中的URL

我有一个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,所以这是预期的(我认为)。

google-chrome docker docker-compose google-chrome-headless
1个回答
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不同。

© www.soinside.com 2019 - 2024. All rights reserved.