0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AlpineのDockerイメージでHeadless Chromeのエラーを抑制する(D-Bus)

Posted at

問題

こちらのDocker上のAlpine Linuxの場合になる。同様にD-Bus関連のエラーがたくさん沢山出る。

対応

最低限のDockerfileとentrypoint.shで示す。

上記の記事の通りD-Busが必要なのと、D-Busが電源管理に使うUPowerがないとエラーが出るのでそれらをインストールし、エントリーポイントでD-Busを起動させる。

Dockerfile
FROM alpine

RUN apk add --no-cache \
    chromium \
    dbus \
    upower

WORKDIR /tmp

COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["sh", "/entrypoint.sh"]
entrypoint.sh
#!/bin/sh

mkdir -p /var/run/dbus
dbus-daemon --system --fork --nopidfile --syslog-only
export XDG_RUNTIME_DIR=/run/user/$(id -u)
export DBUS_SESSION_BUS_ADDRESS=unix:path=$XDG_RUNTIME_DIR/bus
mkdir -p $XDG_RUNTIME_DIR
chmod 700 $XDG_RUNTIME_DIR
chown $(id -un):$(id -gn) $XDG_RUNTIME_DIR
dbus-daemon --session --address=$DBUS_SESSION_BUS_ADDRESS --fork --nopidfile --syslog-only

exec sh -c "$*"

ビルド(とりあえずイメージ名はhogeで…)

$ docker build -t hoge .

D-Busが動いているか?

$ docker run -it -v ${PWD}:/tmp hoge ps -e
PID   USER     TIME  COMMAND
    1 root      0:00 ps -e
    9 messageb  0:00 dbus-daemon --system --fork --nopidfile --syslog-only
   17 root      0:00 dbus-daemon --session --address=unix:path=/run/user/0/bus --fork --nopidfile --syslog-only

スクリーンショットで試す

$ docker run -it -v ${PWD}:/tmp hoge \
  chromium-browser \
    --enable-logging \
    --headless \
    --disable-gpu \
    --disable-software-rasterizer \
    --no-sandbox \
    --screenshot \
    http://ifconfig.io
50635 bytes written to file screenshot.png

Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory他諸々のエラーは出なくなる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?