Centos6 + python2.7 で pip がインストールできなかった話…

docker で centos6 + python2.7 の環境を作成するために、下のリンク dockerfile を使用したが pip がインストールできなかったので備忘録として残しておきます。
tleyden5iwx/centos-6-python-2.7

エラー1

下記のようなエラーが出ます。

#9 5.715   File "<stdin>", line 1
#9 5.715     404: Not Found
#9 5.715        ^
#9 5.715 SyntaxError: invalid syntax

下のリンクが 404 なのが原因みたいです。

https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py

エラー2

下記のサイトを参考に URL を差し替えます。(パイプの前まで)
pipのインストール方法

curl -kL https://bootstrap.pypa.io/get-pip.py | python2.7 - && \

またしてもエラー。
しかしエラーに指定のURLがあるのでそれに差し替えて実行してみます。

ERROR: This script does not work on Python 2.7 The minimum supported Python version is 3.6. Please use https://bootstrap.pypa.io/pip/2.7/get-pip.py instead.

エラー3

またしてもエラー。
依存の関係で 2.1 以下のバージョンを探しているけどないって事っぽい。

#9 5.720 ERROR: Could not find a version that satisfies the requirement pip<21.0 (from versions: none)
#9 5.720 ERROR: No matching distribution found for pip<21.0
【日本語訳】
#9 5.720 エラー: 要件 pip<21.0 を満たすバージョンが見つかりませんでした (バージョンから: なし)
#9 5.720 エラー: pip<21.0 の一致する分布が見つかりません

エラー4

下記のサイトを参考に dockerfile に追記して yum でインストールしてみます。
CentOS6でpipを使う

# dockerfile
python-pip \

またしても pip で失敗しているようです。

/bin/sh: pip: command not found

エラー5

今度は下の記事を試してみます。
Python 2.7 に pip をインストールする

curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py && \
python2.7 get-pip.py && \
pip install -r requirements.txt

最初のと同じエラー。

#9 5.509 ERROR: Could not find a version that satisfies the requirement pip<21.0 (from versions: none)
#9 5.510 ERROR: No matching distribution found for pip<21.0

エラー6

下のサイトにいろいろ書いてあるが、easy_install も無事失敗。
CentOS6にPython2.7をインストール

解決

下記の記事に 2.7.9 なら pip が同梱されてると記載がある...
CentOS6にPython2.7をインストール
dockerfile を下記の通りに書き換えて再度 docker-compose build を実行。

# Install setuptools + pip
RUN cd /tmp && \
    wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-1.4.2.tar.gz && \
    tar -xvf setuptools-1.4.2.tar.gz && \
    cd setuptools-1.4.2 && \
    python2.7 setup.py install && \
    curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py && \
    python2.7 get-pip.py

無事 get-pip が成功。
文章で書くと短いけどずっとハマってました...

YouTube