Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker image with python3, chromedriver, chrome & selenium

My objective is to scrape the web with Selenium driven by Python from a docker container.

I've looked around for and not found a docker image with all of the following installed:

  • Python 3
  • ChromeDriver
  • Chrome
  • Selenium

Is anyone able to link me to a docker image with all of these installed and working together?

Perhaps building my own isn't as difficult as I think, but it's alluded me thus far.

Any and all advice appreciated.

like image 657
goose Avatar asked Dec 23 '17 19:12

goose


1 Answers

Try https://github.com/SeleniumHQ/docker-selenium.

It has python installed:

$ docker run selenium/standalone-chrome python3 --version
Python 3.5.2

The instructions indicate you start it with

docker run -d -p 4444:4444 --shm-size=2g selenium/standalone-chrome

Edit:

To allow selenium to run through python it appears you need to install the packages. Create this Dockerfile:

FROM selenium/standalone-chrome

USER root
RUN wget https://bootstrap.pypa.io/get-pip.py
RUN python3 get-pip.py
RUN python3 -m pip install selenium

Then you could run it with

docker build . -t selenium-chrome && \
    docker run -it selenium-chrome python3

The advantage compared to the plain python docker image is that you won't need to install the chromedriver itself since it comes from selenium/standalone-chrome.

like image 134
Harald Nordgren Avatar answered Sep 28 '22 17:09

Harald Nordgren