在Alpine docker容器中运行geckodriver [英] Running geckodriver in an Alpine docker container

查看:152
本文介绍了在Alpine docker容器中运行geckodriver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Alpine 3.10 docker容器中运行GeckoDriver v0.26.0,特别是 python:3.6.6-alpine3.10

I'm trying to run GeckoDriver v0.26.0 inside an Alpine 3.10 docker container, specifically python:3.6.6-alpine3.10.

弄清楚一些事情之后,我碰壁了:

After figuring some things out, I've hit a wall:

/ # geckodriver --version
Error relocating /usr/bin/geckodriver: __register_atfork: symbol not found
Error relocating /usr/bin/geckodriver: __res_init: symbol not found

我想念什么?

首先启动docker容器:

First spin up the docker container:

docker run -it python:3.6.9-alpine3.10 /bin/sh

然后尝试安装GeckoDriver

Then try installing GeckoDriver

/ # wget https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz
/ # tar -zxf geckodriver-v0.26.0-linux64.tar.gz -C /usr/bin
/ # geckodriver --version
/bin/sh: geckodriver: not found.

真的吗?但我只是提取了它...嗯...好提取正确吗? $ PATH 是否正确?

Really? but I just extracted it... Hmm... OK. Did it extract correctly? Is $PATH correct?

/ # ls -lah /usr/bin/geckodriver
-rwxr-xr-x    1 1000     1000        6.7M Oct 12 10:19 /usr/bin/geckodriver
/ # echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

是。好吧,让我们用谷歌搜索。好吧,也许我应该检查文件信息

Yes. OK, Let's google things. Well perhaps I should check the file info. Alpine doesn't have that by default.

/ # apk add file
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/community/x86_64/APKINDEX.tar.gz
(1/2) Installing libmagic (5.37-r1)
(2/2) Installing file (5.37-r1)
Executing busybox-1.30.1-r2.trigger
OK: 24 MiB in 36 packages
/ # file /usr/bin/geckodriver
/usr/bin/geckodriver: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.26, BuildID[sha1]=32c4cfc2d9346336dc7c20e99a62df9be344d609, with debug_info, not stripped

同一问题的答案说要检查 /lib64/ld-linux-x86-64.so.2

/ # ls /lib64
ls: /lib64: No such file or directory

丢失。好的,我们如何得到呢? 高山软件包回购表示,它是 libc6-compat 的一部分。酷安装,一切都会起作用...对吧?

Missing. OK, how do we get that? The Alpine package repo says it's part of libc6-compat. Cool install that and things will work... right?

/ # apk add libc6-compat
(1/1) Installing libc6-compat (1.1.22-r3)
OK: 24 MiB in 37 packages
/ # ls /lib64
ld-linux-x86-64.so.2
/ # geckodriver --version
Error loading shared library libgcc_s.so.1: No such file or directory (needed by /usr/bin/geckodriver)
Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /usr/bin/geckodriver)
Error relocating /usr/bin/geckodriver: __register_atfork: symbol not found
Error relocating /usr/bin/geckodriver: _Unwind_Resume: symbol not found
Error relocating /usr/bin/geckodriver: __res_init: symbol not found
Error relocating /usr/bin/geckodriver: _Unwind_GetIP: symbol not found
Error relocating /usr/bin/geckodriver: _Unwind_Backtrace: symbol not found

...至少它能识别它现在作为可执行文件...好,所以我们需要 libgcc_s.so.1 这在libgcc中

... Well at least it recognizes it as an executable file now... OK, so we need libgcc_s.so.1. That's in libgcc. Makes sense.

/ # apk add libgcc
(1/1) Installing libgcc (8.3.0-r0)
OK: 24 MiB in 38 packages
/ # geckodriver --version
Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /usr/bin/geckodriver)
Error relocating /usr/bin/geckodriver: __register_atfork: symbol not found
Error relocating /usr/bin/geckodriver: __res_init: symbol not found

什么?我们在 / lib64 中有 ld-linux-x86-64.so.2 ,它在哪里?我确实注意到 gcompat 软件包为 /lib/ld-linux-x86-64.so.2

What? We have ld-linux-x86-64.so.2 in /lib64, where's it looking? I did notice that the gcompat package as /lib/ld-linux-x86-64.so.2, maybe it's looking there?

# / apk add gcompat
(1/2) Installing libucontext (0.1.3-r1)
(2/2) Installing gcompat (0.4.0-r0)
OK: 24 MiB in 40 packages
# / geckodriver --version
Error relocating /usr/bin/geckodriver: __register_atfork: symbol not found
Error relocating /usr/bin/geckodriver: __res_init: symbol not found

这就是我的位置。谷歌搜索 __ register_atfork __ res_init 不会返回任何有用的信息。

And that's where I'm at. Googling for __register_atfork and __res_init don't return anything useful.

推荐答案

因此,此问题的根本原因似乎是Alpine使用 musl libc 和GeckoDriver(间接)使用 glibc

So the root cause of the issue appears to be that Alpine uses musl libc and GeckoDriver (indirectly) uses glibc.

SGerrand具有出色的用于Alpine Linux的glibc兼容性层软件包我们将利用。

SGerrand has a great glibc compatibility layer package for Alpine Linux which we'll make use of.

# Get all the prereqs
wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.30-r0/glibc-2.30-r0.apk
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.30-r0/glibc-bin-2.30-r0.apk
apk add glibc-2.30-r0.apk
apk add glibc-bin-2.30-r0.apk

# And of course we need Firefox if we actually want to *use* GeckoDriver
apk add firefox-esr=60.9.0-r0

# Then install GeckoDriver
wget https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz
tar -zxf geckodriver-v0.26.0-linux64.tar.gz -C /usr/bin
geckodriver --version



注意事项:




  • 仅在 python:3.6.9-alpine3.10 docker镜像上进行测试。

  • Alpine 3.10仅具有Firefox ESR60。幸运的是GeckoDriver v0.26的最低版本为FireFox60。


    • Alpine Edge分支具有Firefox-ESR 86和Firefox 70

    • Caveats:

      • Only tested on the python:3.6.9-alpine3.10 docker image.
      • Alpine 3.10 only has Firefox ESR 60. Luckily GeckoDriver v0.26 has a minimum version of FireFox 60.
        • The Alpine Edge branch has Firefox-ESR 86 and Firefox 70.
        • 这篇关于在Alpine docker容器中运行geckodriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆