# See https://codeship.com/documentation/docker/browser-testing/ | |
FROM myapp:base | |
# We need wget to set up the PPA and xvfb to have a virtual screen and unzip to install the Chromedriver | |
RUN apt-get install -y wget xvfb unzip | |
# Set up the Chrome PPA | |
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - | |
RUN echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list | |
# Update the package list and install chrome | |
RUN apt-get update -y | |
RUN apt-get install -y google-chrome-stable | |
# Set up Chromedriver Environment variables | |
ENV CHROMEDRIVER_VERSION 2.19 | |
ENV CHROMEDRIVER_DIR /chromedriver | |
RUN mkdir $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 | |
# Put Chromedriver into the PATH | |
ENV PATH $CHROMEDRIVER_DIR:$PATH |
I still get an error. Can someone help me with it? @JoaRiski
This is my dockerfile,
`FROM python:3.6
RUN pip install --upgrade pip && pip install pytest && pip install pytest-mock && pip install pytest-smtp && pip install mock
pip install schedule && pip install selenium && pip install Selenium-Screenshot && pip install python-dateutil
COPY src/screenshotcode.py /
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list
RUN apt-get update -y
RUN apt-get install -y google-chrome-stable
RUN apt-get install libxi6 libgconf-2-4 -y
ENV CHROMEDRIVER_VERSION 2.19
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
Put Chromedriver into the PATH
ENV PATH $CHROMEDRIVER_DIR:$PATH
CMD [ "python", "screenshotcode.py" ]`
This is my python code,
import time
from Screenshot import Screenshot_Clipping
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
from email_it import email_it
from environmental_variables import environmental_variables
from error_alert_email import error_alert_email
from selenium import webdriver
def screenshot():
ob=Screenshot_Clipping.Screenshot()
chrome_options = Options()
chrome_options.add_argument('--start-maximized')
chrome_options.add_argument('--start-fullscreen')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
driver = webdriver.Chrome(executable_path = '$CHROMEDRIVER_DIR:$PATH')
print('taking screenshot...')
img_url=ob.full_Screenshot(driver, path = path, image_name = label)
print('closing driver...')
driver.close()
screenshot()
Did you try it with the example provided in a single RUN
block instead of being spread across multiple?
Hi guys, I'm trying to use the single RUN but I'm facing this error:
`debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
Configuring tzdata
Please select the geographic area in which you live. Subsequent configuration
questions will narrow this down by presenting a list of cities, representing
the time zones in which they are located.
- Africa 6. Asia 11. System V timezones
- America 7. Atlantic Ocean 12. US
- Antarctica 8. Europe 13. None of the above
- Australia 9. Indian Ocean
- Arctic Ocean 10. Pacific Ocean
Geographic area: 12
`
After selecting the Area the build process is frozen
I'm using the UBUNTU 20.04 image
FROM public.ecr.aws/ubuntu/ubuntu:20.04
@rootlinux I literally have not used github public in so long but I was running into the same issue trying to install chrome in my Dockerfile. Below is what fixed it for me.
# Set up timezone for google-chrom-stable question
ENV TZ=US
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
Hopefully this helps!
@JoaRiski that is brilliant. Was looking for a way line up stable_dev of chrome with chromedriver but for some reason they don't offer anything of the sort. Thanks for adding this!
+1 - thank you!
pull access denied for myapp, repository does not exist or may require 'docker login'
I got that error , what should i do ?
Were you able to fix this issue?
I am also getting same error
I adapted this to fetch the latest version of chrome driver appropriate for the chrome installation, rather than having a fixed value. Here's the snippet I use for installing:
RUN apt-get update && \ apt-get install -y gnupg wget curl unzip --no-install-recommends && \ wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \ echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list && \ apt-get update -y && \ apt-get install -y google-chrome-stable && \ CHROMEVER=$(google-chrome --product-version | grep -o "[^\.]*\.[^\.]*\.[^\.]*") && \ DRIVERVER=$(curl -s "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROMEVER") && \ wget -q --continue -P /chromedriver "http://chromedriver.storage.googleapis.com/$DRIVERVER/chromedriver_linux64.zip" && \ unzip /chromedriver/chromedriver* -d /chromedriver
This works perfectly !!!
Thank you so much @JoaRiski
I need this code for GCP as app engine that automatically run the chrome driver as Docker . I put this code but still has error. what should I put the path for chrome driver?
@robertkhaldar I am having the same issue, I am able to run the dockerfile and I reference the path (/usr/local/bin/chromedriver) in webdriver.ChromeOptions(). I still receive a "Error: Message: 'chromedriver' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home" when executing in my function app.
uname -a local 21.1.0 Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:24 PDT 2021; root:xnu-8019.41.5~1/RELEASE_ARM64_T8101 arm64
my app FROM python:3.9
all code similar, but i get executor failed running [/bin/sh -c apt-get install -y wget xvfb unzip]: exit code: 100
cause of missing apt-get update before
ok, thats fine and easy fixable, but i get Unable to locate package google-chrome-stable
upd
fixed that using --platform linux/x86_64
this works in my case, FROM python:3.9-slim-bullseye with Debian 11 and Python 3.9.9 and I'm using https://github.com/mherrmann/selenium-python-helium
RUN apt-get update && \
apt-get install -y gnupg wget curl unzip --no-install-recommends && \
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list && \
apt-get update -qqy && \
apt-get -qqy install \
${CHROME_VERSION:-google-chrome-stable} && \
rm /etc/apt/sources.list.d/google-chrome.list && \
rm -rf /var/lib/apt/lists/* /var/cache/apt/*
ARG CHROME_DRIVER_VERSION
RUN if [ -z "$CHROME_DRIVER_VERSION" ]; \
then CHROME_MAJOR_VERSION=$(google-chrome --version | sed -E "s/.* ([0-9]+)(\.[0-9]+){3}.*/\1/") \
&& CHROME_DRIVER_VERSION=$(wget --no-verbose -O - "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_MAJOR_VERSION}"); \
fi \
&& echo "Using chromedriver version: "$CHROME_DRIVER_VERSION \
&& wget --no-verbose -O /tmp/chromedriver_linux64.zip https://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip \
&& rm -rf /opt/selenium/chromedriver \
&& unzip /tmp/chromedriver_linux64.zip -d /opt/selenium \
&& rm /tmp/chromedriver_linux64.zip \
&& mv /opt/selenium/chromedriver /opt/selenium/chromedriver-$CHROME_DRIVER_VERSION \
&& chmod 755 /opt/selenium/chromedriver-$CHROME_DRIVER_VERSION \
&& ln -fs /opt/selenium/chromedriver-$CHROME_DRIVER_VERSION /usr/bin/chromedriver
Guys, this works for me.
FROM python:3.10.2-bullseye
RUN apt-get update -y
# We need wget to set up the PPA and xvfb to have a virtual screen and unzip to install the Chromedriver
RUN apt-get install -y wget xvfb unzip
# Set up the Chrome PPA
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list
# Update the package list and install chrome
RUN apt-get update -y
RUN apt-get install -y google-chrome-stable
# Set up Chromedriver Environment variables
ENV CHROMEDRIVER_VERSION 97.0.4692.71
ENV CHROMEDRIVER_DIR /chromedriver
RUN mkdir $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
# Put Chromedriver into the PATH
ENV PATH $CHROMEDRIVER_DIR:$PATH
To achieve the proper Google Chrome/chromedriver combination, you'll want to heed the instructions on this page: https://chromedriver.chromium.org/downloads/version-selection
Basically, you'll want to get the latest Chrome and install it, then get the product version from that Chrome installation (google-chrome -product-version
), use that version information to build the URL to get the correct chromedriver version information from chromedriver.storage.googleapis.com, allowing you to build the specific download URL for the correct chromedriver version.
@Amogh Katwe
did you get a solutionn ?!
Guys, this works for me.
FROM python:3.10.2-bullseye RUN apt-get update -y # We need wget to set up the PPA and xvfb to have a virtual screen and unzip to install the Chromedriver RUN apt-get install -y wget xvfb unzip # Set up the Chrome PPA RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - RUN echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list # Update the package list and install chrome RUN apt-get update -y RUN apt-get install -y google-chrome-stable # Set up Chromedriver Environment variables ENV CHROMEDRIVER_VERSION 97.0.4692.71 ENV CHROMEDRIVER_DIR /chromedriver RUN mkdir $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 # Put Chromedriver into the PATH ENV PATH $CHROMEDRIVER_DIR:$PATH
@lane-eb Thank you
This ^^ approach will not work for the long term. If you were to install Google Chrome on most platforms today, your version would be 101.xxx.xxx.xxx -- a version 97 chromedriver won't work with today's Chrome without having to re-determine the chromedriver version and update the Dockerfile accordingly.
Currently, I do this:
RUN apt-get update && \
apt-get install -y gnupg wget curl unzip --no-install-recommends && \
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list && \
apt-get update -y && \
apt-get install -y google-chrome-stable && \
CHROME_VERSION=$(google-chrome --product-version | grep -o "[^\.]*\.[^\.]*\.[^\.]*") && \
CHROMEDRIVER_VERSION=$(curl -s "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROME_VERSION") && \
wget -q --continue -P /chromedriver "http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip" && \
unzip /chromedriver/chromedriver* -d /usr/local/bin/
It has worked consistently for several months over several Chrome updates.
This ^^ approach will not work for the long term. If you were to install Google Chrome on most platforms today, your version would be 101.xxx.xxx.xxx -- a version 97 chromedriver won't work with today's Chrome without having to re-determine the chromedriver version and update the Dockerfile accordingly.
Currently, I do this:
RUN apt-get update && \ apt-get install -y gnupg wget curl unzip --no-install-recommends && \ wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \ echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list && \ apt-get update -y && \ apt-get install -y google-chrome-stable && \ CHROME_VERSION=$(google-chrome --product-version | grep -o "[^\.]*\.[^\.]*\.[^\.]*") && \ CHROMEDRIVER_VERSION=$(curl -s "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROME_VERSION") && \ wget -q --continue -P /chromedriver "http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip" && \ unzip /chromedriver/chromedriver* -d /usr/local/bin/
It has worked consistently for several months over several Chrome updates.
Thank You @mnaumann-plenty, saved my day.
This is up to date version what worked for me with ruby container as it sets correct path with: /usr/local/bin/
Now in container chromedriver responds to: chromedriver -v
And updated it a bit https://gist.github.com/Faq/8821c5fd18dd01da4f80d7435158096d
Thanks @JoaRiski