I have a working docker container and want migrate to a lambda layer for selenium 3.141 on firefox. Dockerfile for the working container is:
FROM python:3.7-slim
RUN /usr/local/bin/python -m pip install --upgrade pip
RUN pip install selenium==3.141.0
RUN apt-get update
RUN apt-get -y install wget bzip2 firefox-esr #68.12.0esr
WORKDIR /tmp
RUN wget https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz
RUN tar -zxf geckodriver-v0.26.0-linux64.tar.gz -C /usr/local/bin/
When I execute the following in this container a Firefox
object is created.
from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options
opts = Options()
opts.headless = True
Firefox(options=opts, service_log_path='/home/geckodriver.log')
For the lambda layer I use an amazonlinux
image for local testing. On aws a zip file I provide will be extracted into /opt
, so I want to put everything into /opt
and see if it works.
My dockerfile for that is
FROM amazonlinux
WORKDIR /
RUN yum update -y
# Install Python 3.7
RUN yum install python3 zip unzip wget tar bzip2 bzip2-libs gzip -y
RUN pip3.7 install --upgrade pip
RUN pip3.7 install selenium==3.141.0 #-t /opt/python/lib/python3.7/site-packages
RUN wget https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz
RUN tar -zxf geckodriver-v0.26.0-linux64.tar.gz -C /opt
RUN wget https://ftp.mozilla.org/pub/firefox/releases/68.9.0esr/linux-x86_64/de/firefox-68.9.0esr.tar.bz2
RUN tar -xvjf firefox-68.9.0esr.tar.bz2 -C /opt
But when I run that with
sudo docker build -t selenium:fftest -f Dockerfile.ff .
sudo docker run --rm -it -v $(pwd):/data selenium:fftest
and execute
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver import Firefox
opts = Options()
opts.headless = True
firefox_dir = '/opt/'
gecko_dir = '/opt/'
binary = FirefoxBinary( firefox_dir + 'firefox/firefox')
Firefox(options=opts, executable_path= gecko_dir + 'geckodriver', firefox_binary=binary)
I get
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
keep_alive=True)
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: invalid argument: can't kill an exited process
I've tried
checking version compatibility
This answer https://stackoverflow.com/a/52535654/3014199 suggests version incompatibilities but according to the table I'm fine with selenium 3.141, Geckodriver 22 and Firefox 68.
running it as a non-root user
The linked answer further suggests running as a non root user. I've finally managed to do that with:
FROM amazonlinux
RUN yum update -y
RUN yum install python3 wget tar bzip2 bzip2-libs gzip -y
Run yum install shadow-utils -y
RUN useradd -ms /bin/bash jd
RUN echo "jd:password" | chpasswd
RUN usermod -aG root jd
USER jd
WORKDIR /home/jd
RUN pip3.7 install --user --upgrade pip
RUN pip3.7 install --user selenium==3.141.0
COPY downloads/geckodriver-v0.26.0-linux64.tar.gz /tmp/
COPY downloads/firefox-68.9.0esr.tar.bz2 /tmp/
USER root
RUN tar -zxf /tmp/geckodriver-v0.26.0-linux64.tar.gz -C /opt
RUN tar -xvjf /tmp/firefox-68.9.0esr.tar.bz2 -C /opt
RUN chown -R jd:jd /opt/firefox
USER jd
Everything in /opt
has jd
as owner and group, but the error message is the same.
extracting everything into /usr/local/bin
When I extract both geckodriver and firefox into /usr/local/bin
I cann instantiate with just Firefox(options=opts)
but get the same can't kill an exited process
error.
inspecting the binaries
$ /opt/firefox/firefox --version
XPCOMGlueLoad error for file /opt/firefox/libmozgtk.so:
libgtk-3.so.0: cannot open shared object file: No such file or directory
Couldn't load XPCOM.
I think the missing object file is the root cause. But I don't know where to get it and where to put it(I can only put it in /opt
).
After yum install gtk3-devel
libdbus-glib-1.so.2
is missing for file /opt/firefox/libxul.so
.