Issue
I am new to Docker. I have used it to create an image of my project. When I try to build the image using a Dockerfile in which I install the needed libraries as well as Google Chrome and ChromeDriver I get an error message indicating a mismatch between ChromeDriver & Google Chrome.
Here's a portion of the Dockerfile :
# 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/
Once the docker image is launched, whenever I try to execute a script of my project I get this error message :
> selenium.common.exceptions.SessionNotCreatedException: Message:
> session not created: This version of ChromeDriver only supports Chrome
> version 114 Current browser version is 116.0.5845.110 with binary path
> /opt/google/chrome/google-chrome Stacktrace:
> #0 0x56061f6b04e3 <unknown>
> #1 0x56061f3dfc76 <unknown>
> #2 0x56061f40d04a <unknown>
> #3 0x56061f4084a1 <unknown>
> #4 0x56061f405029 <unknown>
> #5 0x56061f443ccc <unknown>
> #6 0x56061f44347f <unknown>
> #7 0x56061f43ade3 <unknown>
> #8 0x56061f4102dd <unknown>
> #9 0x56061f41134e <unknown>
> #10 0x56061f6703e4 <unknown>
> #11 0x56061f6743d7 <unknown>
> #12 0x56061f67eb20 <unknown>
> #13 0x56061f675023 <unknown>
> #14 0x56061f6431aa <unknown>
> #15 0x56061f6996b8 <unknown>
> #16 0x56061f699847 <unknown>
> #17 0x56061f6a9243 <unknown>
> #18 0x7f72cb9de044 <unknown>
Here's how I initialize chrome in my code:
from selenium import webdriver
....
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(options=options)
Now I know that http://chromedriver.storage.googleapis.com is no longer supported but how can I modify the Dockerfile to make sure that I always get compatible Chrome & ChromeDriver versions ?
Solution
For those having the same issue, I solved it by simply using an official Selenium Docker image instead of installing Chrome & ChromeDriver seperately.
I removed Chrome & ChromeDriver installation from my Dockerfile and added this line :
# Use an official Selenium Docker image that provides compatible Chrome and ChromeDriver versions
FROM selenium/standalone-chrome:latest
In this case, the official Selenium Docker image already includes the necessary Chrome and ChromeDriver versions that are compatible with each other.
Answered By - Mejdi Dallel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.