2015-09-26 84 views
7

當我建立我的碼頭工人形象時,得到這樣的警告:InsecurePlatformWarning建設碼頭工人形象

/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 
+0

嘗試使用--upgrade標誌,例如:'RUN pip install --upgrade pyopenssl ndg-httpsclient pyasn1' – dopstar

+0

沒有運氣(這是有道理的,因爲沒有存在ng包,以便在Docker映像生成時升級 - 除非我誤解'pip install --upgrade')。 –

+0

嘗試在'RUN apt-get install -y libffi-dev libssl-dev'中添加'libpython2.7-dev'。 'pip安裝請求[安全性]'而不是'pip install pyopenssl'更好' – ahmed

回答

2

似乎運行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 

,然後運行該容器內:

[email protected]:/# 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