python - Docker - 安装烧瓶失败
问题描述
我在 Ubuntu 16.04 上运行 docker-ce。在构建我的自定义应用程序时,它失败了,因为它无法安装 Python 应用程序所需的 Flask。
我支持我组织的代理,所以我也使用了内联代理。但它仍然失败。
Dockerfile:
RUN pip install -r requirements.txt \
--proxy https://10.70.52.146:3128 \
--trusted-host pypi.python.org
要求.txt:
Flask
Redis
输出:
Step 7/10 : RUN pip install -r requirements.txt --proxy https://10.70.52.146:3128 --trusted-host pypi.python.org<br/>
---> Running in 3d92822e4d79<br/>
Collecting Flask (from -r requirements.txt (line 1))
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, u'EOF occurred in violation of protocol (_ssl.c:661)'),)': /packages/7f/e7/08578774ed4536d3242b14dacb4696386634607af824ea997202cd0edb4b/Flask-1.0.2-py2.py3-none-any.whl<br/>
Could not install packages due to an EnvironmentError:<br/>HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/7f/e7/08578774ed4536d3242b14dacb4696386634607af824ea997202cd0edb4b/Flask-1.0.2-py2.py3-none-any.whl (Caused by SSLError(SSLEOFError(8, u'EOF occurred in violation of protocol (_ssl.c:661)'),))
The command '/bin/sh -c pip install -r requirements.txt --proxy http://10.70.52.146:3128 --trusted-host pypi.python.org' returned a non-zero code: 1
这个错误指的是什么?
解决方案
将HTTP_PROXY
和HTTPS_PROXY
环境变量设置为构建参数应该可以解决您的问题。
Dockerfile:
FROM python:3.6
ADD requirements.txt requirements.txt
RUN pip install -r requirements.txt
构建命令:
docker build --build-arg HTTP_PROXY=https://10.70.52.146:3128 --build-arg HTTPS_PROXY=https://10.70.52.146:3128 .
在 Dockerfile 之外设置代理地址也是一种更好的做法,因为它允许您从组织网络之外重用此 Dockerfile。
推荐阅读
- javascript - 从打字稿中的正则表达式生成随机字符串
- python - 如何更改元组中的数据类型?
- javascript - javascript = vs == 带有 if 和 else 语句
- bash - 获取第一次出现值的行号?
- javascript - 在闪亮的移动设备中访问对话框提示上的取消按钮的值
- javascript - recaptcha v3 表单未提交
- json - 用 jq 转换 json 对象,用 base64 解码转换值
- python - Python字符串提取之间
- javascript - 如何将视图中创建的变量用作操作结果中的参数?(ASP.NET MVC)
- javascript - NodeJS req.body 在功能 nodejs 中为空 - 带有 ExpressJs 和续集的 Rest API