0
  • 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

1
  • The standard Python image certainly does not include a GUI, let alone then Chrome or Firefox. You'll need to set up quite a bit of software by hand, or find a better image to start from. Look for a "headless browser" image perhaps; adding Python and Selenium to that should be a lot easier. Commented Mar 27, 2022 at 14:17

1 Answer 1

1

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"]
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you so much, this should help! Could you please explain what is WORKDIR /app -#python file that u want to run? Do I still need to specify the path to the python file I want to run in the CMD?
According to this documentation docs.docker.com/engine/reference/builder/#workdir , The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile. If the WORKDIR doesn’t exist, it will be created even if it’s not used in any subsequent Dockerfile instruction. I believe that i work as a working directory so that it can perform the specific instructions. you should run the docker image using the command "docker run <image_name>. I believe u can retrieve the image name using the command "docker images"
Feel free to ask here again if you encountered any problems . I would be willing to help you :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.