【问题标题】:InsecurePlatformWarning when building Docker image构建 Docker 映像时出现 InsecurePlatformWarning
【发布时间】:2015-12-23 21:26:40
【问题描述】:

我在构建 Docker 映像时收到此警告:

/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:79: 
      InsecurePlatformWarning: A true SSLContext object is not available. 
      This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. 
      For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.

多个消息来源(如InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately)表示pip install pyopenssl ndg-httpsclient pyasn1 将解决此问题。但是一旦 pip 尝试安装 pyopenssl,我就会收到警告。

这是我的 Dockerfile:

FROM ubuntu:14.04

# Install packages
RUN apt-get update && apt-get install -y \
    git \
    libmysqlclient-dev \
    mysql-server \
    nginx \
    python-dev \
    python-mysqldb \
    python-setuptools \
    supervisor \
    vim
RUN easy_install pip

# Handle urllib3 InsecurePlatformWarning
RUN apt-get install -y libffi-dev libssl-dev
RUN pip install pyopenssl ndg-httpsclient pyasn1

# ...more

【问题讨论】:

  • 尝试使用 --upgrade 标志,例如:RUN pip install --upgrade pyopenssl ndg-httpsclient pyasn1
  • 运气不好(这是有道理的,因为在构建 Docker 映像时没有可供 pip 升级的现有软件包——除非我误解了pip install --upgrade)。
  • 尝试在RUN apt-get install -y libffi-dev libssl-dev 中添加libpython2.7-dev。最好pip install requests[security] 而不是pip install pyopenssl
  • 谢谢,但还是没有运气。
  • 你可以尝试直接从Ubuntu发行版安装urllib3和相关包,我认为是python-urllib3。

标签: python ubuntu docker pip urllib3


【解决方案1】:

运行 pip:http://github.com/pypa/pip/issues/2681 时似乎会出现此警告,但在安装 pyopenssl ndg-httpsclient pyasn1 时,使用 python 请求时不会收到警告。

例如,如果我构建这个 Dockerfile:

FROM ubuntu:14.04

# Install packages
RUN apt-get update && apt-get install -y \
    git \
    libmysqlclient-dev \
    mysql-server \
    nginx \
    python-dev \
    python-mysqldb \
    python-setuptools \
    supervisor \
    vim
RUN easy_install pip
RUN pip install requests

然后在容器内运行:

root@b2759f79f947:/# python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> import requests

>>> url = "https://www.digicert.com/"

>>> r = requests.get(url)

/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:100: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.

  InsecurePlatformWarning

如您所见,我收到了警告。 但是如果我在 Dockerfile 中添加这些行:

RUN apt-get install -y libffi-dev libssl-dev
RUN pip install pyopenssl ndg-httpsclient pyasn1

并运行相同的 python 命令,我不再收到警告。

如果你真的不想在安装pyopenssl时出现警告,你可以设置环境变量:PYTHONWARNINGS="ignore:a true SSLContext object"这里建议:https://github.com/pypa/pip/pull/3109

您的 Dockerfile 将如下所示:

FROM ubuntu:14.04

# Install packages
RUN apt-get update && apt-get install -y \
    git \
    libmysqlclient-dev \
    mysql-server \
    nginx \
    python-dev \
    python-mysqldb \
    python-setuptools \
    supervisor \
    vim
RUN easy_install pip

# Handle urllib3 InsecurePlatformWarning
RUN apt-get install -y libffi-dev libssl-dev
ENV PYTHONWARNINGS="ignore:a true SSLContext object"
RUN pip install pyopenssl ndg-httpsclient pyasn1

另一种解决方案是将 python 升级到 2.7.9

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-23
    • 1970-01-01
    • 1970-01-01
    • 2018-01-13
    相关资源
    最近更新 更多