Chrome 如何使用debian docker镜像运行chromium headless?

jc3wubiy  于 2023-05-20  发布在  Go
关注(0)|答案(1)|浏览(256)

我在dockerhub上看到过一些chrome的无头镜像,但是我想基于debian构建我自己的镜像。

FROM buildpack-deps:bookworm

RUN apt update && apt install -y chromium
chromium --headless --no-sandbox --disable-gpu --disable-software-rasterizer --disable-dev-shm-usage
[0518/234805.581627:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[0518/234805.586145:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[0518/234805.586179:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[0518/234805.590590:WARNING:bluez_dbus_manager.cc(247)] Floss manager not present, cannot set Floss enable/disable.

我如何解决这个问题?是否严格要求DBUS?这个问题是如何解决的?
这里描述的解决方案(添加--remote-debugging-port=9222参数)对我不起作用:Headless chromium in ubuntu docker container

sg3maiej

sg3maiej1#

好吧,我意识到,即使返回这些错误并立即退出,它仍然“工作”。
例如,通过传递额外的参数,它可以实现预期的效果(比如截图):

docker run \
--rm -it \
-v $PWD:/mypwd \
-w /mypwd \
--entrypoint chromium \
mydockerimage \
--headless \
--no-sandbox \
--disable-gpu \
--disable-software-rasterizer \
--disable-dev-shm-usage \
--screenshot \
--hide-scrollbars \
https://www.chromestatus.com/

相关问题