jlandure / alpine-chrome

Chrome Headless docker images built upon alpine official image
https://hub.docker.com/r/zenika/alpine-chrome
Apache License 2.0
1.89k stars 245 forks source link

Failed to write file pdf: No such file or directory (2) when using `print-to-pdf` #223

Open frederikhors opened 1 year ago

frederikhors commented 1 year ago

Hi guys! Thank you for your amazing work!

I'm trying to build a custom Dockerfile using your one:

FROM alpine:3.17

RUN apk upgrade --no-cache --available \
    && apk add --no-cache \
      chromium-swiftshader \
      ttf-freefont \
      font-noto-emoji \
    && apk add --no-cache \
      --repository=https://dl-cdn.alpinelinux.org/alpine/edge/testing \
      font-wqy-zenhei

# I tried with these too, same error
# RUN mkdir -p /usr/src/app \
#     && adduser -D chrome \
#     && chown -R chrome:chrome /usr/src/app

# USER chrome
# WORKDIR /usr/src/app

ENV CHROME_BIN=/usr/bin/chromium-browser \
    CHROME_PATH=/usr/lib/chromium/

ENV CHROMIUM_FLAGS="--disable-dev-shm-usage --disable-software-rasterizer"

COPY ./app/ .

CMD ./start.sh

start.sh is like this:

#!/bin/sh

# other things here

./app

The app starts. The app calls chrome with the below OS command (from dir /usr/bin):

chromium-browser --headless --no-sandbox --disable-setuid-sandbox --disable-gpu --disable-dev-shm-usage --run-all-compositor-stages-before-draw --print-to-pdf='/tmp/test.pdf' /tmp/test.html

Chrome starts but errors with:

[0206/124936.861070:WARNING:dns_config_service_linux.cc(429)] Failed to read DnsConfig.\n
[0206/124936.861016:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory\n
[0206/124936.861200:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory\n
[0206/124936.868371:WARNING:bluez_dbus_manager.cc(247)] Floss manager not present, cannot set Floss enable/disable.\n
[0206/124936.893388:WARNING:sandbox_linux.cc(385)] InitializeSandbox() called with multiple threads in process gpu-process.\n
[0206/124936.969693:WARNING:dns_config_service_linux.cc(429)] Failed to read DnsConfig.\n
[0206/124937.140474:ERROR:headless_shell.cc(219)] Failed to write file '/tmp/test.pdf': No such file or directory (2)\n"

As you can see the MAIN error is: Failed to write file '/tmp/test.pdf': No such file or directory (2)\n"

What is causing this?

Is this a permissions issue?

zigarn commented 1 year ago

What is the execution context? How do you run the container?

Cannot reproduce it on direct call to chromium-browser ... --print-to-pdf='/tmp/test.pdf' ... from an image built from the dockerfile you gave.

$ cat Dockerfile 
FROM alpine:3.17

RUN apk upgrade --no-cache --available \
    && apk add --no-cache \
      chromium-swiftshader \
      ttf-freefont \
      font-noto-emoji \
    && apk add --no-cache \
      --repository=https://dl-cdn.alpinelinux.org/alpine/edge/testing \
      font-wqy-zenhei

# I tried with these too, same error
# RUN mkdir -p /usr/src/app \
#     && adduser -D chrome \
#     && chown -R chrome:chrome /usr/src/app

# USER chrome
# WORKDIR /usr/src/app

ENV CHROME_BIN=/usr/bin/chromium-browser \
    CHROME_PATH=/usr/lib/chromium/

ENV CHROMIUM_FLAGS="--disable-dev-shm-usage --disable-software-rasterizer"

$ docker image build -t test .
[+] Building 27.5s (7/7) FINISHED                                                                                                                                                                                                             
 => [internal] load build definition from Dockerfile
 => => transferring dockerfile: 657B
 => [internal] load .dockerignore
 => => transferring context: 2B
 => [internal] load metadata for docker.io/library/alpine:3.17
 => [auth] library/alpine:pull token for registry-1.docker.io
 => [1/2] FROM docker.io/library/alpine:3.17@sha256:124c7d2707904eea7431fffe91522a01e5a861a624ee31d03372cc1d138a3126
 => => resolve docker.io/library/alpine:3.17@sha256:124c7d2707904eea7431fffe91522a01e5a861a624ee31d03372cc1d138a3126
 => => sha256:9ed4aefc74f6792b5a804d1d146fe4b4a2299147b0f50eaf2b08435d7b38c27e 1.47kB / 1.47kB
 => => sha256:124c7d2707904eea7431fffe91522a01e5a861a624ee31d03372cc1d138a3126 1.64kB / 1.64kB
 => => sha256:b6ca290b6b4cdcca5b3db3ffa338ee0285c11744b4a6abaa9627746ee3291d8d 528B / 528B
 => [2/2] RUN apk upgrade --no-cache --available     && apk add --no-cache       chromium-swiftshader       ttf-freefont       font-noto-emoji     && apk add --no-cache       --repository=https://dl-cdn.alpinelinux.org/alpine/edge
 => exporting to image
 => => exporting layers
 => => writing image sha256:21a08a622a103c30aabf55b2e2b5671240dd5cc0c95866ec5c74d813c163ec80
 => => naming to docker.io/library/test

$ docker run -it test /bin/sh                                                                                                                          
/ # chromium-browser --headless --no-sandbox --disable-setuid-sandbox --disable-gpu --disable-dev-shm-usage --run-all-compositor-stages-before-draw --print-to-pdf='/tmp/test.pdf' /tmp/test.html
[0510/100150.474000:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
[0510/100150.487552:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
[0510/100150.487759:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
[0510/100150.488013:WARNING:dns_config_service_linux.cc(429)] Failed to read DnsConfig.
[0510/100150.496589:WARNING:bluez_dbus_manager.cc(247)] Floss manager not present, cannot set Floss enable/disable.
[0510/100150.509475:WARNING:sandbox_linux.cc(393)] InitializeSandbox() called with multiple threads in process gpu-process.
[0510/100150.558819:WARNING:dns_config_service_linux.cc(429)] Failed to read DnsConfig.
4576 bytes written to file /tmp/test.pdf
/ #