gpt4 book ai didi

google-chrome - docker 官方 dind 构建 (docker :latest) with chromiuim

转载 作者:行者123 更新时间:2023-12-02 20:31:06 24 4
gpt4 key购买 nike

过去两天我一直在尝试在 docker:latest docker 镜像上安装和运行 chromuim。 ( docker 中的 docker )。

我尝试了多个 docker 文件:

from docker:latest

RUN apk add --no-cache python py2-pip curl bash chromuim ttf-freefont xvfb nodejs nodejs-npm udev
RUN curl -sSL https://sdk.cloud.google.com | bash
ENV PATH $PATH:~/google-cloud-sdk/bin

RUN pip install docker-compose
RUN npm install -g @angular/cli swagger
ENV CHROME_BIN=/usr/bin/chromium-browser

这安装了不支持 headless 的 chrome 57。
所以我怀疑我可以用 xvbf 运行它,但是运行这个 chrome 失败了:
Failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Operation not permitted
[8:8:1124/085514.600081:FATAL:zygote_host_impl_linux.cc(182)] Check failed: ReceiveFixedMessage(fds[0], kZygoteBootMessage, sizeof(kZygoteBootMessage), &boot_pid).
Aborted (core dumped)

所以我尝试安装 chrome 61(支持 headless )。
但为此,您需要更新 Dockerfile 以使用 edge。
我尝试立即升级/或安装 61。我总是缺少字体。
我得到的最接近的是调整我的 dockerfile 以使用 lighthose 之一
from docker:latest

RUN apk add --no-cache python py2-pip curl bash xvfb nodejs nodejs-npm udev
RUN curl -sSL https://sdk.cloud.google.com | bash
ENV PATH $PATH:~/google-cloud-sdk/bin

RUN pip install docker-compose
RUN npm install -g @angular/cli swagger
ENV CHROME_BIN=/usr/bin/chromium-browser

USER root

RUN echo "http://dl-2.alpinelinux.org/alpine/edge/main" > /etc/apk/repositories
RUN echo "http://dl-2.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
RUN echo "http://dl-2.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories

#-----------------
# Set ENV and change mode
#-----------------
ENV LIGHTHOUSE_CHROMIUM_PATH /usr/bin/chromium-browser

ENV TZ "Europe/Berlin"
ENV DEBIAN_FRONTEND noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN true
ENV SCREEN_WIDTH 750
ENV SCREEN_HEIGHT 1334
ENV SCREEN_DEPTH 24
ENV DISPLAY :99.0
ENV PATH /lighthouse/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

ENV GEOMETRY "$SCREEN_WIDTH""x""$SCREEN_HEIGHT""x""$SCREEN_DEPTH"

RUN echo $TZ > /etc/timezone

#-----------------
# Add packages
#-----------------

RUN apk -U --no-cache update
RUN apk -U --no-cache add \
zlib-dev \
chromium \
freetype \
ttf-opensans \
xvfb \
wait4ports \
xorg-server \
dbus \
ttf-freefont \
mesa-dri-swrast


# Minimize size

RUN apk del --purge --force curl make gcc g++ python linux-headers binutils-gold gnupg git zlib-dev apk-tools libc-utils

RUN rm -rf /var/lib/apt/lists/* \
/var/cache/apk/* \
/usr/share/man \
/tmp/* \
/usr/lib/node_modules/npm/man \
/usr/lib/node_modules/npm/doc \
/usr/lib/node_modules/npm/html \
/usr/lib/node_modules/npm/scripts

VOLUME /lighthouse/output

ADD xvfb-chromium.sh /chromium-xvfb.sh
RUN chmod +x /chromium-xvfb.sh

xvfb-chromium.sh (虽然不需要,因为你可以 docker run/bin/bash 进入容器)
#!/bin/sh

_kill_procs() {
kill -TERM $chromium
wait $chromium
kill -TERM $xvfb
}

parameters=$@


# We need to test if /var/run/dbus exists, since script will fail if it does not

[ ! -e /var/run/dbus ] && mkdir /var/run/dbus

/usr/bin/dbus-daemon --system

# Setup a trap to catch SIGTERM and relay it to child processes
trap _kill_procs SIGTERM

TMP_PROFILE_DIR=`mktemp -d -t chromium.XXXXXX`
export CHROME_DEBUGGING_PORT=9222

# Start Xvfb
Xvfb ${DISPLAY} -ac +iglx -screen 0 ${GEOMETRY} -nolisten tcp & xvfb=$!

printf "Starting xvfb window server..."

while [ 1 -gt $xvfb ]; do printf "..."; sleep 1; done

printf "xvfb started\n\n"

#printf "Starting chromium, with debugger on port $CHROME_DEBUGGING_POST...\n\n"

# --disable-webgl \

$CHROME_BIN \
--no-sandbox \
--user-data-dir=${TMP_PROFILE_DIR} \
--start-maximized \
--remote-debugging-port=${CHROME_DEBUGGING_PORT} \
--no-first-run "about:blank" &

#chromium=$!

#wait4ports tcp://127.0.0.1:$CHROME_DEBUGGING_PORT

printf "\n\n==============================\nlaunching lighthouse run\n==============================\n\n"

#wait $chromium
wait $xvfb

然后我得到另一个错误:
Error relocating /usr/lib/chromium/chrome: FT_Set_Default_Properties: symbol not found

不知道如何解决这个问题,任何帮助将不胜感激。

最佳答案

你可以试试这个链接https://github.com/c0b/chrome-in-docker
它从 chrome channel 下载 google-chrome Linux 版本,无论是稳定版,还是 beta 版,或者开发者版;它把 google-chrome 变成了一个 headless 浏览器,

关于google-chrome - docker 官方 dind 构建 (docker :latest) with chromiuim,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47469692/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com