由于从 https://pypi.python.org/simple/ 返回 'Move Permanently' 错误,`pip` 无法在 Docker 容器内安装包

`pip` failed to install package inside Docker container due to 'Move Permanently' error returned from `https://pypi.python.org/simple/`

我想在 Ubuntu 14.04 docker 容器中安装 pip 包,但由于从 https://pypi.python.org/simple/ 返回 Move Permanently,它总是显示错误。奇怪的(?)点是主机 运行 Ubuntu 14.04 和相同版本的 python & pip 成功安装了 pip 包。

Docker版本:

$ docker --version
Docker version 1.12.6-cs13, build 0ee24d4

Docker文件:(注意:为了测试,我特意进入了容器内部)。

FROM ubuntu:14.04
RUN apt-get update
RUN apt-get -qq install python python-pip
WORKDIR /usr/src/app
COPY . .
CMD ["/bin/sh"]

在主机上:

$ uname -a
Linux duong2179-ubuntu 4.4.0-31-generic #50~14.04.1-Ubuntu SMP Wed Jul 13 01:07:32 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
$ python --version
Python 2.7.6
$ pip --version
pip 1.5.4 from /usr/lib/python2.7/dist-packages (python 2.7)
$ sudo pip install simplejson==3.3.1
Downloading/unpacking simplejson==3.3.1
...
Successfully installed simplejson

容器内:

# uname -a
Linux duong2179-ubuntu 4.4.0-31-generic #50~14.04.1-Ubuntu SMP Wed Jul 13 01:07:32 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
# python --version
Python 2.7.6
# pip --version
pip 1.5.4 from /usr/lib/python2.7/dist-packages (python 2.7)
# pip install simplejson==3.3.1
Downloading/unpacking simplejson==3.3.1
  Cannot fetch index base URL https://pypi.python.org/simple/
  Could not find any downloads that satisfy the requirement simplejson==3.3.1

从主机做 curl-ing https://pypi.python.org/simple/:

$ curl https://pypi.python.org/simple/
<html><head><title>301 Moved Permanently</title></head><body><center><h1>301 Moved Permanently</h1></center></body></html>

这是 pip 1.5.4

的已知问题

在使用 pip 之前将以下行添加到您的 Dockerfile

RUN python -m pip install --upgrade pip