Home > Mobile >  Can't containerise Python app with Docker
Can't containerise Python app with Docker

Time:03-28

  • I have a multi-directory Python Selenium app that I want to put into a container with Docker

  • I don't have experience with this tech, so I tried making a Dockerfile this way Dockerfile:

    FROM python:3.8 COPY ./* ./

    RUN pip install selenium pytest pytest-html

    CMD python /tests/form_page/test_form_page.py

  • I want this Python app run from a container

  • I also uderstand that I need to add a venv (probably) and a Chrome driver for this app to work, but I don't know how to do this

Could you please help me out on this one?

PS if this would help here's the source code https://github.com/anatolyRozhkov/RozhkovPetProject.git

CodePudding user response:

I believe that you have install Google Chrome browser and Chrome driver inside your Dockerfile. Then build the docker image in your container and run your docker images using the command docker run <image_name>:latest

FROM python:3.8

# install google chrome
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
RUN apt-get -y update
RUN apt-get install -y google-chrome-stable

# install chromedriver
RUN apt-get install -yqq unzip
RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip
RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/

# set display port to avoid crash
ENV DISPLAY=:99

RUN pip install selenium
RUN pip install pytest

WORKDIR /app -#python file that u want to run
COPY . /app

CMD ["python", "/tests/form_page/test_form_page.py"]
  • Related