Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dockerfile with chromedriver
# 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
@dnlserrano

This comment has been minimized.

Copy link

@dnlserrano dnlserrano commented Jun 27, 2017

Thanks man! 👍

@ORESoftware

This comment has been minimized.

Copy link

@ORESoftware ORESoftware commented Nov 6, 2017

why not use the default path of

/usr/bin/google-chrome

?

@xxholyChalicexx

This comment has been minimized.

Copy link

@xxholyChalicexx xxholyChalicexx commented Dec 3, 2018

FROM myapp:base...... which image are you using?

@vladdoster

This comment has been minimized.

Copy link

@vladdoster vladdoster commented Jan 5, 2019

FROM myapp:base...... which image are you using?

I think it is just a placeholder for an image that supports the commands!

@simonneutert

This comment has been minimized.

Copy link

@simonneutert simonneutert commented Mar 29, 2019

you, sir, deserve an award for this! 🎉

@maram2012

This comment has been minimized.

Copy link

@maram2012 maram2012 commented Aug 21, 2019

pull access denied for myapp, repository does not exist or may require 'docker login'
I got that error , what should i do ?

@tomreitsma

This comment has been minimized.

Copy link

@tomreitsma tomreitsma commented Sep 1, 2019

@maram2012 it's a placeholder.. you should provide your own image base

@JoaRiski

This comment has been minimized.

Copy link

@JoaRiski JoaRiski commented Jan 30, 2020

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
@Benji4

This comment has been minimized.

Copy link

@Benji4 Benji4 commented Feb 25, 2020

The mkdir command needs option -p:
RUN mkdir -p $CHROMEDRIVER_DIR

The Chromedriver must be made executable:
RUN chmod +x $CHROMEDRIVER_DIR/chromedriver

Chromedriver might need these packages:
RUN apt-get install libxi6 libgconf-2-4 -y

Also possibly, chrome might need to be run with option --no-sandbox, but not sure; might be a security issue.

Thank you for the Dockerfile! Really made my day!

@jagruthim

This comment has been minimized.

Copy link

@jagruthim jagruthim commented Mar 4, 2020

I am using below docker and I face the issue driver not found and Selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/chromium is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
How can this issue be resolved?

FROM python:3.8-buster RUN apt-get update && apt-get install -yq \ chromium \ git-core \ xvfb=2:1.20.4-1 \ xsel=1.2.0+git9bfc13d.20180109-1 \ unzip=6.0-23+deb10u1 \ python-pytest=3.10.1-2 \ libgconf-2-4=3.2.6-5 \ libncurses5=6.1+20181013-2+deb10u2 \ libxml2-dev \ libxslt-dev \ libz-dev \ xclip=0.13-1

@bruno-ds

This comment has been minimized.

Copy link

@bruno-ds bruno-ds commented Mar 19, 2020

FYI, Selenium provide a way similar Dockerfile :
https://github.com/SeleniumHQ/docker-selenium/blob/master/NodeChrome/Dockerfile

Personnaly, I'm still trying to understand how to interract with the container once built (an example would be great!)

@shogester

This comment has been minimized.

Copy link

@shogester shogester commented May 28, 2020

@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!

@Vasavi-MN

This comment has been minimized.

Copy link

@Vasavi-MN Vasavi-MN commented Nov 10, 2020

Could anyone help to modify docker file for chrome and chrome driver install on windows 2016 server

@avinashpatel57

This comment has been minimized.

Copy link

@avinashpatel57 avinashpatel57 commented Mar 10, 2021

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

Thanks @JoaRiski

@ppetruneac

This comment has been minimized.

Copy link

@ppetruneac ppetruneac commented Mar 23, 2021

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

Thanks @JoaRiski

@AmoghKatwe

This comment has been minimized.

Copy link

@AmoghKatwe AmoghKatwe commented Apr 21, 2021

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()
@JoaRiski

This comment has been minimized.

Copy link

@JoaRiski JoaRiski commented May 11, 2021

Did you try it with the example provided in a single RUN block instead of being spread across multiple?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment