I'm trying to set up web scraping using Selenium in a Docker container, and I've crafted this Dockerfile,but I'm hitting a roadblock because it doesn't seem to work as expected. Here's my Dockerfile for reference:
```
FROM python:3.11-slim
# Installing the necessary dependencies
RUN apt-get update && apt-get install -y --no-install-recommends
vim
chromium
chromium-driver
&& rm -rf /var/lib/apt/lists/*
# Set environment variables
ENV CHROME_BIN=/usr/bin/chromium
ENV CHROME_DRIVER=/usr/bin/chromedriver
# Set working directory
WORKDIR /app
# Copy files
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
# Expose port 8000 for Django
EXPOSE 8000
# Start the Django server
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
```
When I build the image, I get errors. Can someone help diagnose what might be going wrong?
2 Answers
You might want to try using one of the official Selenium base images instead of starting from the basic Python slim image. These images are pre-configured with everything needed for Selenium to work properly. Check out the [Selenium Docker repository](https://github.com/SeleniumHQ/docker-selenium) for some good starting points.
It looks like you're encountering a `SessionNotCreatedException`. This error generally means that your ChromeDriver version doesn't match the version of Chrome you're trying to use. According to the error message, your ChromeDriver only supports Chrome version 114, but the version you're running is 136.0.7103.59. Make sure you update your ChromeDriver to a compatible version!
Yeah, the error message clearly states the version mismatch! Just update ChromeDriver and it should work.
Exactly! It’s right there in the stacktrace. Just a quick update to ChromeDriver should fix the problem.