Reputation: 53
The quick description of the problem is:
app
and test
test
to reach public URLstest
to successfully curl to app
test
to load URLs that on the docker-compose network in chrome headlessI have a docker-compose file with two services like so:
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:
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?
Here's a complete repo that shows the problem: 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.
NOTE 2: Regarding the ERROR:ssl_client_socket_impl
, the app doesn't expose SSL, so this is to be expected (I think).
Upvotes: 0
Views: 1795
Reputation: 53
I can't tell exactly why yet, but changing the service name from app
to something other than app
fixes it:
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
.
Upvotes: 1