Skip to content

Instantly share code, notes, and snippets.

@hltbra
Created April 2, 2018 18:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hltbra/785e0c50ea9ddac84ef45057cb88c7ed to your computer and use it in GitHub Desktop.
Save hltbra/785e0c50ea9ddac84ef45057cb88c7ed to your computer and use it in GitHub Desktop.
Running a PoC of selenium + chromium + python
docker build -t chromefull:1 .
# Google Chrome needs some kernel permissions,
# more details at https://github.com/jessfraz/dockerfiles/issues/65 and https://serverfault.com/a/824920
docker run --rm --cap-add=SYS_ADMIN chromefull:1
from __future__ import print_function
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://httpbin.org/ip")
print("IP: {}".format(driver.page_source))
driver.get("https://httpbin.org/headers")
print("Headers: {}".format(driver.page_source))
FROM python:2.7
RUN apt-get update && \
apt-get install -y --no-install-recommends \
xvfb \
chromium \
chromedriver
RUN pip install selenium
COPY app.py /app.py
COPY run.sh /run.sh
RUN chmod +x /run.sh
RUN useradd -r -U chrome
USER chrome
WORKDIR /tmp
ENV PATH=/usr/local/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/chromium
ENV DISPLAY=:99
CMD /run.sh
#!/bin/bash
Xvfb :99 -screen 0 1440x900x24 &> /tmp/xvfb_log.txt &
python /app.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment