Skip to content

4.13.1 (90346) Docker crash when running container with selenium and chrome #6530

Closed

Description

  • I have tried with the latest version of Docker Desktop
  • I have tried disabling enabled experimental features
  • I have uploaded Diagnostics
  • Diagnostics ID: 5b5ed26e-0021-4de6-8651-9305b4039bb3/20221021175526

Expected behavior

Single run python script executes and uses selenium and chrome to scrape target website then done. Been doing this for almost 3 years daily.

Actual behavior

After upgrading to Docker Desktop for Mac 4.13.0, the docker engine crashes with this message in the terminal that launched the container with docker run command. I thought the issue might have been fixed in 4.13.1 but it is still occurring, though less frequently/reliably than before.

ERRO[0007] error waiting for container: invalid character 'c' looking for beginning of value

The menu bar icon shows the engine stopping...the dashboard shows engine stopped but trying to restart from the docker menu fails with a fatal error. Screenshot attached. You have to exit/quit docker and restart it for the engine to become operational again.

Screen Shot 2022-10-21 at 1 59 38 PM

Information

  • macOS Version: Monterey 12.6
  • Intel chip or Apple chip: Intel
  • Docker Desktop Version: 4.13.0 & 4.13.1

Output of /Applications/Docker.app/Contents/MacOS/com.docker.diagnose check

This output is before running the container and causing the crash. If I run this after the crash, of course it generates a bunch of errors about not being able to reach the docker services. I can post that as well but figured you cared more to know that before each run, the base docker installation is healthy.

Starting diagnostics

[PASS] DD0027: is there available disk space on the host?
[PASS] DD0028: is there available VM disk space?
[PASS] DD0018: does the host support virtualization?
[PASS] DD0001: is the application running?
[PASS] DD0017: can a VM be started?
[PASS] DD0016: is the LinuxKit VM running?
[PASS] DD0011: are the LinuxKit services running?
[PASS] DD0004: is the Docker engine running?
[PASS] DD0015: are the binary symlinks installed?
[PASS] DD0031: does the Docker API work?
[PASS] DD0013: is the $PATH ok?
[PASS] DD0003: is the Docker CLI working?
[PASS] DD0014: are the backend processes running?
[PASS] DD0007: is the backend responding?
[PASS] DD0008: is the native API responding?
[PASS] DD0009: is the vpnkit API responding?
[PASS] DD0010: is the Docker API proxy responding?
[PASS] DD0012: is the VM networking working?
[SKIP] DD0030: is the image access management authorized?
[PASS] DD0019: is the com.docker.vmnetd process responding?
[PASS] DD0033: does the host have Internet access?
[PASS] DD0018: does the host support virtualization?
[PASS] DD0001: is the application running?
[PASS] DD0017: can a VM be started?
[PASS] DD0016: is the LinuxKit VM running?
[PASS] DD0011: are the LinuxKit services running?
[PASS] DD0004: is the Docker engine running?
[PASS] DD0015: are the binary symlinks installed?
[PASS] DD0031: does the Docker API work?
[PASS] DD0032: do Docker networks overlap with host IPs?
No fatal errors detected.

Steps to reproduce the behavior

  1. Dockerfile
# For more information, please refer to https://aka.ms/vscode-docker-python
FROM python:3.10-slim

# Install packages we are going to need for setting up Chrome
RUN apt-get update && apt-get install -y \
    gnupg \
    wget \
    curl \
    unzip \
    && rm -rf /var/lib/apt/lists/*

# 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 update && apt-get install -y \
    google-chrome-stable \
    && rm -rf /var/lib/apt/lists/*

# Install chromedriver
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/ && rm /tmp/chromedriver.zip

# Set display port to avoid crashing Chrome
ENV DISPLAY=:99

# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1

# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1

# Install pip requirements
ADD requirements.txt .
RUN python -m pip install -r requirements.txt

WORKDIR /app
ADD ./src /app

# Switching to a non-root user, please refer to https://aka.ms/vscode-docker-python-user-rights
RUN useradd appuser && chown -R appuser /app
USER appuser

# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
CMD ["python", "app.py"]
  1. Run this app.py to cause the fault, you may have to run it a few times before the crash will occur but it only takes 1-3 tries reliably on my machine.
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

class Scraper:
    def __init__(self, delay):
        # Let's grab our default settings for Chromium instance
        chrome_options = self.__build_chrome_options()
        self.delay = delay

        try:
            # Let's instantiate our scraper
            self.driver = webdriver.Chrome(options=chrome_options)
        except Exception as e:
            raise e

    def __build_chrome_options(self):
        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument('--window-size=1920,1200')
        chrome_options.add_argument('--headless')
        chrome_options.add_argument('--single-process')
        chrome_options.add_argument('--no-sandbox')
        chrome_options.add_argument('--disable-gpu')
        chrome_options.add_argument('--enable-logging')
        chrome_options.add_argument('--user-data-dir=/tmp/user1')
        chrome_options.add_argument('--v=1')
        chrome_options.add_argument('--ignore-certificate-errors')
        chrome_options.add_argument('--disable-dev-shm-usage')

        return chrome_options

    def scroll_down(self, delay):
        while True:
            # Get scroll height.
            lastHeight = self.driver.execute_script("return document.body.scrollHeight")

            # Scroll down to the bottom. 
            print(f"Last height: [{lastHeight}] - Scrolling...") # uncomment for debugging scrolling
            self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

            # Wait to load the page
            sleep(delay/2)

            # Calculate new scroll height and compare with last scroll height
            newHeight = self.driver.execute_script("return document.body.scrollHeight")

            # If the browser hasn’t scrolled any more (i.e. it’s reached the end) then stop
            if newHeight == lastHeight:
                print("Reached bottom") # uncomment for debugging scrolling
                break

    def get_with_delay(self, request_url, delay):
        self.driver.get(request_url)
        sleep(delay)
        self.scroll_down(delay)
    
    def __del__(self):
        self.driver.quit()

# use this for testing locally
if __name__ == "__main__":
    scraper = Scraper(3)

    url = "https://abcnews.go.com/"

    try:
        print("Getting url: ", url)
        scraper.get_with_delay(url, 3)
    except Exception as e:
        print(f'Error {e} while scraping url: {url}')

You should just need to add selenium to a requirements.txt file and/or install it on running container to get the test code to work on top of the base python image. I tried to see if the issue was python, base linux in container and/or selenium version rooted but same result with python 3.8, 3.9 and 3.10, selenium 4.2, 4.3, 4.4, 4.5 and both buster and bullseye distros. Hope this is helpful in fixing for future Docker release.

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

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions