Docker file for Chromium with python

  docker, python, selenium-webdriver

main.py

from selenium import webdriver

if __name__ =="__main__":
    options = webdriver.ChromeOptions()
    options.headless = True
    browser = webdriver.Chrome('/usr/local/chromedriver', options=options)
    browser.get("some-url")

requirements.txt

selenium
chromedriver-py

DockerFile

FROM python:3.7
ARG PYTHON_VERSION="3.7"
ENV PYTHON="python${PYTHON_VERSION}"
ENV LC_ALL=en_US.UTF-8
ENV LANG=en_US.UTF-8

WORKDIR /opt/sample
COPY ./requirements.txt  /opt/sample

RUN pip3 install -r requirements.txt

# need here to setup chromedriver for docker run

COPY ./app /opt/sample


CMD ["python3.7", "./app.py"]

# Ports - App
EXPOSE 4781

I am learning docker and writing docker files . Here i have a main file where i have specified path manually by downloading the chrome driver on my mac Os and it runs fully . Now i want to containerise the application and run on server .I am facing issues in setting up path for chromeDriver via docker.

How can we download and setup the path for chromeDriver via docker? And what changed needs to be done in { main.py , requirements.txt, DockerFile}. Any help is appreciated

Source: Docker Questions

LEAVE A COMMENT