12

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

What am I missing?

How I got here

First spin up the docker container:

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

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.

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

The answer to that same question says to check for /lib64/ld-linux-x86-64.so.2:

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

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

... 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

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

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

dthor
  • 1,749
  • 1
  • 18
  • 45

1 Answers1

17

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

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

To get GeckoDriver running on Alpine:

# 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

Caveats:

dthor
  • 1,749
  • 1
  • 18
  • 45
  • Looks like some of the links are dead `wget: can't open 'glibc-2.30-r0.apk': File exists` – radtek Feb 26 '20 at 17:12
  • Do you already have `glibc-2.30-r0.apk` in your current working dir? The URLs all still work for me. Well, the `musl libc` website changed, but that's not part of the code to get geckodriver working on alpine. – dthor Feb 26 '20 at 17:27
  • Doesn't work from wget- `Connecting to github.com (192.30.253.112:443) Connecting to github-production-release-asset-2e65be.s3.amazonaws.com (52.216.129.195:443) wget: can't open 'glibc-2.30-r0.apk': File exists` – radtek Feb 26 '20 at 17:33
  • 1
    Anyways works for me without installing those. One thing to note is to run it headless .. in my case running form selenium - https://stackoverflow.com/questions/52534658/webdriverexception-message-invalid-argument-cant-kill-an-exited-process-with see NFerns answer – radtek Feb 26 '20 at 17:45
  • following your directions I get `/usr/src/app # geckodriver --version sh: geckodriver: not found` but clearly the file is there.. not sure why but if I use v 0.22.0 it works. – radtek May 30 '20 at 04:08