0

I am trying to run selenium in docker. first I found a docker image from blueimp.

FROM blueimp/geckodriver
USER root

RUN apt-get update
RUN apt-get install -y --fix-missing x11-utils wget xclip firefox-esr xvfb xsel unzip libncurses5 libxslt-dev libxml2-dev libz-dev npm nodejs
RUN wget -q "https://github.com/mozilla/geckodriver/releases/download/v0.19.1/geckodriver-v0.19.1-linux64.tar.gz" -O /tmp/geckodriver.tgz \
    && tar zxf /tmp/geckodriver.tgz -C /usr/bin/ \
    && rm /tmp/geckodriver.tgz

RUN ln -s /usr/bin/geckodriver \
    && chmod 777 /usr/bin/geckodriver \
RUN /usr/bin/Xvfb :99 -ac -screen 0 1024x768x8 & export DISPLAY=":99"
RUN curl -L https://github.com/mozilla/geckodriver/releases/download/v0.24.0/geckodriver-v0.24.0-linux64.tar.gz > geckodriver-v0.24.0-linux64.tar.gz && tar -xzf geckodriver-v0.24.0-linux64.tar.gz && rm geckodriver-v0.24.0-linux64.tar.gz && mv geckodriver /usr/local/bin && chmod -R 777 /usr/local/bin

COPY package.json /src/package.json

RUN cd /src; npm install

COPY . /src

CMD ["node", "/src/app.js"]

this docker file works fine and builds complete successfully. without xvfb selenium complains with this error: invalid argument: can't kill an exited process .

then according to this answer : https://stackoverflow.com/a/53198328/5677187 you can handle selenuim with some virtual display. but when I try to run my docker container it comes with this error:

xvfb-run : xvfb failed to start

I am entring to running container shell and execute this: Xvfb and the output is :

fatal server error:

(EE) Server is already active for display 0 . if this server is no longer running, remove /tmp/.X0-lock

Babak Abadkheir
  • 2,222
  • 1
  • 19
  • 46
  • 1
    A Dockerfile `RUN` command neither persists running processes nor environment variables; after the `RUN Xvfb ...` line, there is no display manager running and `$DISPLAY` will be unset. If you need a setup with a running display manager to run graphical applications, a virtual machine running an ordinary desktop Linux distribution might be a more natural setup than a Docker container. – David Maze May 19 '20 at 13:56
  • tnx for reply. i will find some way to manage my display on docker. in python there was an library for creating virtual display for selenium. So the whole project is some sort of crawler that client can choose what to crawl and where to crawl with some management system like schaduling , image crawler , content crawler . so i needed some orchestration for this purpose.@ – Babak Abadkheir May 19 '20 at 22:21

0 Answers0