docker容器中的WebDriver超时

docker容器中的WebDriver超时,docker,selenium-webdriver,Docker,Selenium Webdriver,我正在开发一个由gunicorn提供服务的django应用程序。在这个应用程序中,我试图在selenium的帮助下生成整个网页的截图 在我的本地环境中(通过python manage.py runserver启动应用程序),一切正常。但如果我在docker容器中运行它,它会突然停止工作 我的应用程序如下所示: from selenium import webdriver driver = webdriver.PhantomJS() driver.set_window_si

我正在开发一个由gunicorn提供服务的django应用程序。在这个应用程序中,我试图在selenium的帮助下生成整个网页的截图

在我的本地环境中(通过
python manage.py runserver
启动应用程序),一切正常。但如果我在docker容器中运行它,它会突然停止工作

我的应用程序如下所示:

    from selenium import webdriver
    driver = webdriver.PhantomJS()
    driver.set_window_size(1024, 768)
    driver.get(url)
    driver.save_screenshot(filepath)
    driver.quit()
在执行第二行的过程中,我在几秒钟后收到以下错误消息,所有内容都重新启动。 我从来没到过窗户。遗憾的是,错误消息中没有更多信息

[2018-03-19 01:41:36 +0000] [7] [CRITICAL] WORKER TIMEOUT (pid:19)
[2018-03-19 01:41:36 +0000] [19] [INFO] Worker exiting (pid: 19)
[2018-03-19 01:41:36 +0000] [28] [INFO] Booting worker with pid: 28
感谢您的回答,我现在至少收到一条错误消息:

app.views.add_views-77 ERROR 2018-03-19 02:36:24,668: Message: Can not connect to the Service phantomjs
Traceback (most recent call last):
[..]
    driver = webdriver.PhantomJS()
  File "/usr/lib/python3.6/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 56, in __init__
    self.service.start()
  File "/usr/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 104, in start
    raise WebDriverException("Can not connect to the Service %s" % self.path)
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service phantomjs
当我使用
Chrome
(使用alpine软件包存储库中的
chromium
chromium webdriver
)作为webdriver时,我也会体验到同样的行为

docker compose和docker compose都会发生这种情况

Dockerfile:

FROM alpine:3.7

ENV PYTHONUNBUFFERED 1
ENV PHANTOMJS_VERSION 2.1.1

RUN mkdir /code
WORKDIR /code
COPY Pipfile Pipfile.lock ./

RUN apk update && \
 apk add python3 postgresql-libs jpeg-dev git curl fontconfig && \
 apk add --virtual .build-deps gcc python3-dev musl-dev postgresql-dev zlib-dev && \
 mkdir -p /opt && \
 pip3 install --no-cache-dir pipenv && \
 pipenv install --system && \
 curl -L https://github.com/Overbryd/docker-phantomjs-alpine/releases/download/2.11/phantomjs-alpine-x86_64.tar.bz2 | tar xjC /opt && \
 ln -s /opt/phantomjs/phantomjs /usr/bin/phantomjs && \
 apk --purge del .build-deps

COPY . ./

RUN adduser -D noroot
USER noroot  
EXPOSE $PORT

CMD gunicorn app.wsgi --bind 0.0.0.0:$PORT --log-file -
这里有什么问题