简体   繁体   English

构建Docker镜像时的InsecurePlatformWarning

[英]InsecurePlatformWarning when building Docker image

I get this warning when building my Docker image: 我在构建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.

Several sources (like InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately ) say that pip install pyopenssl ndg-httpsclient pyasn1 will fix this issue. 几个来源(如InsecurePlatformWarning:一个真正的SSLContext对象不可用。这可以防止urllib3正确配置SSL )说pip install pyopenssl ndg-httpsclient pyasn1将解决这个问题。 But I get the warning as soon as pip attemps to install pyopenssl. 但是一旦pip尝试安装pyopenssl,我就会收到警告。

Here's my Dockerfile: 这是我的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

It seems that this warning is expected when running pip: http://github.com/pypa/pip/issues/2681 but as you are installing pyopenssl ndg-httpsclient pyasn1 , you won't get warnings when using python requests. 似乎在运行pip时会出现此警告: httppyopenssl ndg-httpsclient pyasn1但是在安装pyopenssl ndg-httpsclient pyasn1时,使用python请求时不会收到警告。

For example, if I build this Dockerfile: 例如,如果我构建这个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

and then run this inside the container: 然后在容器内运行:

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

As you can see, I get the warning. 如你所见,我得到了警告。 But if I add these lines in the Dockerfile: 但是如果我在Dockerfile中添加这些行:

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

and run the same python commands, I don't get the warning anymore. 并运行相同的python命令,我不再收到警告。

If you really don't want the warning when installing pyopenssl, you can set the environment variable: PYTHONWARNINGS="ignore:a true SSLContext object" as suggested here: https://github.com/pypa/pip/pull/3109 如果您在安装pyopenssl时确实不想要警告,可以设置环境变量: PYTHONWARNINGS="ignore:a true SSLContext object"如下所示: https//github.com/pypa/pip/pull/3109

Your Dockerfile would then look like this: 你的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

Another solution would be to upgrade python to 2.7.9 另一个解决方案是将python升级到2.7.9

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM