4
FROM python:3.7
WORKDIR /opt

RUN curl https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -o /chrome.deb
RUN dpkg -i /chrome.deb || apt-get install -yf
RUN rm /chrome.deb


ENV CHROMEDRIVER_VERSION 89.0.4389.23
ENV CHROMEDRIVER_DIR /chromedriver
RUN mkdir -p $CHROMEDRIVER_DIR

# Download and install Chromedriver
RUN wget -q --continue -P $CHROMEDRIVER_DIR "http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip"
RUN unzip $CHROMEDRIVER_DIR/chromedriver* -d $CHROMEDRIVER_DIR
ENV PATH $CHROMEDRIVER_DIR:$PATH
RUN apt-get update
COPY .  .

RUN pip3 install -r requirements.txt

CMD ["python3","code.py"]

code.py

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

try:
    chrome_options = Options()
    chrome_options.add_argument("--headless")
    driver = webdriver.Chrome(options=chrome_options)
    driver.get('google.com')
    print(f'{driver.page_source}')
except Exception as e:
    print(f'111111111 Exception: {e}')

try:
    options = webdriver.ChromeOptions()
    options.headless = True
    driver = webdriver.Chrome(options=options)
    driver.get('google.com')
    print(f'{driver.page_source}')
except Exception as e:
    print(f'222222 Exception: {e}')
print(f'h')

requirements.txt

selenium

When i build this image it build fine , but throws following error on running image

Service chromedriver unexpectedly exited. Status code was: 127

any idea , where i am doing wrong in the Dockerfile. I tried for other posts available but nothing worked for me. My machine os is Mac catalina and was trying to configure the code for remote host, but this is not even working at my local system as well. Is this is the issue I have another OS and configuring another

I tried this post also but nothing worked

Deepak Sharma
  • 41
  • 1
  • 4

1 Answers1

0

Had the same problem. Fixed it by installing chrome-browser.

Please check this answer: How to install Google chrome in a docker container

Leo M
  • 1
  • 2
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 24 '22 at 18:03