Docker 构建Python镜像时,pip使用国内地址的dockerfile模版

 一、问题现象

构建镜像时,使用pip命令打包报错:
Docker 构建Python镜像时,pip使用国内地址的dockerfile模版_第1张图片


二、问题根因

因国内无法访问pip的配置文件中的仓库地址

三、解决办法

这个办法同样适用于:物理机,这个地址是阿里云的

pip config set global.index-url http://mirrors.aliyun.com/pypi/simple/ 
pip config set install.trusted-host mirrors.aliyun.com
FROM python:3.8

COPY . /app
RUN pip config set global.index-url http://mirrors.aliyun.com/pypi/simple/
RUN pip config set install.trusted-host mirrors.aliyun.com
WORKDIR /app

RUN pip install flask

CMD ["python", "app.py"]

四、其他仓库地址

  • 阿里云:http://mirrors.aliyun.com/pypi/simple/
  • 中国科学技术大学:https://pypi.mirrors.ustc.edu.cn/simple/
  • 清华大学:https://pypi.tuna.tsinghua.edu.cn/simple/
  • 豆瓣:https://pypi.douban.com/simple/

你可能感兴趣的:(记录学习或工作中遇到的问题,云原生,docker,python,pip)