通过 Docker 容器上的主管运行无头 Chrome

通过 Docker 容器上的主管运行无头 Chrome

为了快速运行,我尝试通过主管运行无头 chrome,然后另一个脚本将通过 puppeteer 使用它来执行一些处理。

似乎存在很多权限问题,而且我还没有找到任何关于如何在主管中运行无头 chrome 的有用文章。

我的设置:

导师

[supervisord]
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid
childlogdir=/var/log/supervisorctl
nodaemon=true
user=root

[program:chrome]
command=google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222
user=www-data
autostart=true
autorestart=true
directory=/home/www-data
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

Docker

RUN touch /var/log/supervisor/supervisord.log
RUN chown -R www-data:www-data /var/log/supervisor/supervisord.log
RUN chown -R www-data:www-data /var/log/supervisorctl

CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisor/supervisord.conf"]

由此产生的错误

022-08-31 13:23:23,819 INFO Set uid to user 0 succeeded
2022-08-31 13:23:23,826 INFO supervisord started with pid 1
2022-08-31 13:23:24,831 INFO spawned: 'chrome' with pid 8
2022-08-31 13:23:25,834 INFO success: chrome entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
clone: Invalid argument
[0831/132326.095171:ERROR:scoped_ptrace_attach.cc(27)] ptrace: Function not implemented (38)
qemu: uncaught target signal 5 (Trace/breakpoint trap) - core dumped
2022-08-31 13:23:26,123 INFO reaped unknown pid 40 (exit status 1)
[0831/132326.127281:ERROR:exception_handler_server.cc(142)] tgkill: No such process (3)
qemu: uncaught target signal 5 (Trace/breakpoint trap) - core dumped
2022-08-31 13:23:26,379 INFO exited: chrome (terminated by SIGTRAP; not expected)
2022-08-31 13:23:26,379 INFO reaped unknown pid 32 (exit status 0)

答案1

发生这种情况的原因是我在 M2 Mac 上构建 Docker 容器,--platform=amd64这显然会导致 Chrome 出现很多重大问题,可能还有其他问题。我开始在没有架构虚拟化的 ubuntu 机器上构建,这些问题不再存在。

相关内容