Skip to content

Instantly share code, notes, and snippets.

@varyonic
Created June 10, 2016 14:14
Show Gist options
  • Save varyonic/dea40abcf3dd891d204ef235c6e8dd79 to your computer and use it in GitHub Desktop.
Save varyonic/dea40abcf3dd891d204ef235c6e8dd79 to your computer and use it in GitHub Desktop.
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
@ikotun-dev
Copy link

ikotun-dev commented Apr 26, 2024

This is my current dockerfile

FROM python:3.10.2-bullseye

RUN apt-get update -y && apt-get install -y wget xvfb unzip jq
RUN apt-get install -y libxss1 libappindicator1 libgconf-2-4 \
  fonts-liberation libasound2 libnspr4 libnss3 libx11-xcb1 libxtst6 lsb-release xdg-utils \
  libgbm1 libnss3 libatk-bridge2.0-0 libgtk-3-0 libx11-xcb1 libxcb-dri3-0

RUN curl -s https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json > /tmp/versions.json

RUN CHROME_URL=$(jq -r '.channels.Stable.downloads.chrome[] | select(.platform=="linux64") | .url' /tmp/versions.json) && \
  wget -q --continue -O /tmp/chrome-linux64.zip $CHROME_URL && \
  unzip /tmp/chrome-linux64.zip -d /opt/chrome

RUN chmod +x /opt/chrome/chrome-linux64/chrome


RUN CHROMEDRIVER_URL=$(jq -r '.channels.Stable.downloads.chromedriver[] | select(.platform=="linux64") | .url' /tmp/versions.json) && \
  wget -q --continue -O /tmp/chromedriver-linux64.zip $CHROMEDRIVER_URL && \
  unzip /tmp/chromedriver-linux64.zip -d /opt/chromedriver && \
  chmod +x /opt/chromedriver/chromedriver-linux64/chromedriver

ENV CHROMEDRIVER_DIR /opt/chromedriver
ENV PATH $CHROMEDRIVER_DIR:$PATH

RUN rm /tmp/chrome-linux64.zip /tmp/chromedriver-linux64.zip /tmp/versions.json

WORKDIR /app

COPY requirements.txt ./ 

RUN pip install --no-cache-dir -r requirements.txt

COPY . . 

WORKDIR /app/index/api 

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

@abaezfl
Copy link

abaezfl commented May 2, 2024

@ikotun-dev

If you somehow have docker running directly on the M1 mac, you may run into compatibility issues with the other software the dockerfile is trying to use/obtain, even if you change all the chrome/chromedriver references to use mac-arm64. I didn't attempt it myself, and went with a VM.

If you are running through a VM, your dockerfile should match the architecture of the VM. I had trouble trying to use an arm64 linux VM and changing the dockerfile to match (there is not a "non mac" arm64 chrome/chromedriver), but did have success with an x86 VM on the M1 by installing lima. The dockerfile for linux64 mentioned here worked fine for that.

@ivanesmeral98
Copy link

ankitarya1019

THIS WORKED FOR ME, THANKS SO MUCH! @ankitarya1019

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