Home > Software engineering >  How do I install gecko driver and firefox on my docker image apache/airflow:2.1.4
How do I install gecko driver and firefox on my docker image apache/airflow:2.1.4

Time:10-11

I am trying to use Selenium on one of my airflow tasks. I have airflow running on apache/airflow:2.1.4 docker image.

I get the following error when I use selenium in my airflow task (since I'm missing firefox) FileNotFoundError: [Errno 2] No such file or directory: 'firefox': 'firefox'

How would I go about adding geckodriver and firefox to the airflow image?

I have my docker-compose build the following Dockerfile for airflow,

FROM apache/airflow:2.1.4
WORKDIR /python_dependencies
COPY ./requirements.txt .
RUN pip3 install -r requirements.txt

CodePudding user response:

apache/airflow:2.1.4 is based on debian, so you just need to use apt-get install firefox-esr to get firefox command, while download pre-built binary from geckodriver github to install geckodriver.

Dockerfile:

FROM apache/airflow:2.1.4

USER root
RUN apt-get update                             \
 && apt-get install -y --no-install-recommends \
    ca-certificates curl firefox-esr           \
 && rm -fr /var/lib/apt/lists/*                \
 && curl -L https://github.com/mozilla/geckodriver/releases/download/v0.30.0/geckodriver-v0.30.0-linux64.tar.gz | tar xz -C /usr/local/bin \
 && apt-get purge -y ca-certificates curl
USER airflow

Verify:

$ docker build -t abc:1 .
$ docker run --rm -it --entrypoint=which abc:1 firefox
/usr/bin/firefox
$ docker run --rm -it --entrypoint=which abc:1 geckodriver
/usr/local/bin/geckodriver
  • Related