geoserverの公式dockerイメージにpython2.7 / 3.11インストール

【注意】Dockerイメージ作成後のpythonのライブラリの動作確認は行っていません。

```Dockerfile: Dockerfile
FROM docker.osgeo.org/geoserver:2.23.1

RUN apt update
RUN apt upgrade -y
RUN apt install -y software-properties-common
RUN add-apt-repository ppa:deadsnakes/ppa
RUN apt update && apt install -y \
    python2.7 \
    python2.7-dev \
    python-pip \
    libgdal-dev \
    gdal-bin

RUN update-alternatives --install /usr/bin/python python /usr/bin/python2.7 10

RUN update-alternatives --set python /usr/bin/python2.7

RUN  mkdir /app
WORKDIR /app
COPY requirements.txt /app/
RUN python -m pip install -r requirements.txt

RUN python -V
RUN python -m pip freeze
```

```requirements.txt
numpy==1.16.6
gdal==3.2.3
scikit-learn==0.20.4
shapely==1.7.1
pyproj==2.2.2
fiona==1.8.21
mapnik==0.1
```

```sh
docker build -t example .

～省略～
tep 16/17 : RUN python -V
 ---> Running in 0d2a5cb73d16
Python 2.7.18
Removing intermediate container 0d2a5cb73d16
 ---> fa238fbd9a50
Step 17/17 : RUN python -m pip freeze
 ---> Running in 4e5ed24981d1
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
aenum==3.1.15
attrs==21.4.0
certifi==2021.10.8
click==7.1.2
click-plugins==1.1.1
cligj==0.7.2
enum34==1.1.10
Fiona==1.8.21
GDAL==3.2.3
mapnik==0.1
munch==2.5.0
numpy==1.16.6
pyproj==2.2.2
scikit-learn==0.20.4
scipy==1.2.3
Shapely==1.7.1
six==1.16.0
Removing intermediate container 4e5ed24981d1
 ---> 5e78cdeba030
Successfully built 5e78cdeba030
Successfully tagged example:latest
```

## Python 3.11の場合

【注意】Dockerイメージ作成後のpythonのライブラリの動作確認は行っていません。

```Dockerfile: Dockerfile
FROM docker.osgeo.org/geoserver:2.23.1

RUN apt update
RUN apt upgrade -y
RUN apt install -y software-properties-common
RUN add-apt-repository ppa:deadsnakes/ppa

RUN apt update && apt install -y \
    python3.11 \
    python3-pip \
    libgdal-dev \
    gdal-bin \
    python3-gdal \
    python3-sklearn \
    python3-shapely \
    python3-numpy \
    python3-pyproj \
    python3-fiona \
    python3-mapnik 

RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.11 10

RUN update-alternatives --set python /usr/bin/python3.11

RUN python -V
RUN python -m pip freeze
```

```sh
docker build -t example .

～省略～
Step 9/10 : RUN python -V
 ---> Running in 26cde1ec51cf
Python 3.11.6
Removing intermediate container 26cde1ec51cf
 ---> ebe94275166e
Step 10/10 : RUN python -m pip freeze
 ---> Running in 2260b76ac61c
appdirs==1.4.4
attrs==21.2.0
beautifulsoup4==4.10.0
beniget==0.4.1
blinker==1.4
Brotli==1.0.9
certifi==2020.6.20
chardet==4.0.0
click==8.0.3
click-plugins==1.1.1
cligj==0.7.2
colorama==0.4.4
cryptography==3.4.8
cycler==0.11.0
dbus-python==1.2.18
decorator==4.4.2
distro==1.7.0
distro-info==1.1+ubuntu0.1
Fiona==1.8.21
fonttools==4.29.1
fs==2.4.12
gast==0.5.2
GDAL==3.4.1
html5lib==1.1
httplib2==0.20.2
importlib-metadata==4.6.4
iniconfig==1.1.1
jeepney==0.7.1
joblib==0.17.0
keyring==23.5.0
kiwisolver==1.3.2
launchpadlib==1.10.16
lazr.restfulclient==0.14.4
lazr.uri==1.0.6
lxml==4.8.0
lz4==3.1.3+dfsg
mapnik==3.0.23
matplotlib==3.5.1
more-itertools==8.10.0
mpmath==0.0.0
munch==2.5.0
nose==1.3.7
numpy==1.21.5
oauthlib==3.2.0
olefile==0.46
packaging==21.3
Pillow==9.0.1
pluggy==0.13.0
ply==3.11
psutil==5.9.0
py==1.10.0
pycairo==1.20.1
Pygments==2.11.2
PyGObject==3.42.1
PyJWT==2.3.0
pyparsing==2.4.7
pyproj==3.3.0
pytest==6.2.5
python-apt==2.4.0+ubuntu2
python-dateutil==2.8.1
pythran==0.10.0
pytz==2022.1
scikit-learn==0.23.2
scipy==1.8.0
SecretStorage==3.3.1
Shapely==1.8.0
simplejson==3.17.6
six==1.16.0
soupsieve==2.3.1
sympy==1.9
threadpoolctl==3.1.0
toml==0.10.2
ufoLib2==0.13.1
unattended-upgrades==0.1
unicodedata2==14.0.0
wadllib==1.3.6
webencodings==0.5.1
zipp==1.0.0
Removing intermediate container 2260b76ac61c
 ---> a17089b2fbbd
Successfully built a17089b2fbbd
Successfully tagged example:latest
```

## Python 3.11 (pip install)

【注意】Dockerイメージ作成後のpythonのライブラリの動作確認は行っていません。

```Dockerfile: Dockerfile
FROM docker.osgeo.org/geoserver:2.23.1

RUN apt update
RUN apt upgrade -y
RUN apt install -y software-properties-common
RUN add-apt-repository ppa:deadsnakes/ppa

RUN apt update && apt install -y \
    python3.11 \
    python3.11-dev \
    python3-pip \
    libgdal-dev \
    gdal-bin \
    python3-mapnik \
    libmapnik3.1 \
    mapnik-utils

RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.11 10

RUN update-alternatives --set python /usr/bin/python3.11

RUN  mkdir /app
WORKDIR /app
COPY requirements.txt /app/
RUN python -m pip install -r requirements.txt

# GDAL installation
RUN pip install GDAL==$(gdal-config --version) --global-option=build_ext --global-option="-I/usr/include/gdal"

RUN python -V
RUN python -m pip freeze
```

```requirements.txt
numpy
scikit-learn
shapely
pyproj
fiona
```

```sh
docker build -t example .

～省略～
Step 14/15 : RUN python -V
 ---> Running in dd48d6c0dd42
Python 3.11.6
Removing intermediate container dd48d6c0dd42
 ---> 92e6c355327a
Step 15/15 : RUN python -m pip freeze
 ---> Running in 851418d0d58d
attrs==23.1.0
blinker==1.4
certifi==2023.7.22
click==8.1.7
click-plugins==1.1.1
cligj==0.7.2
cryptography==3.4.8
dbus-python==1.2.18
distro==1.7.0
distro-info==1.1+ubuntu0.1
fiona==1.9.5
GDAL==3.4.1
httplib2==0.20.2
importlib-metadata==4.6.4
jeepney==0.7.1
joblib==1.3.2
keyring==23.5.0
launchpadlib==1.10.16
lazr.restfulclient==0.14.4
lazr.uri==1.0.6
mapnik==3.0.23
more-itertools==8.10.0
numpy==1.26.1
oauthlib==3.2.0
pycairo==1.20.1
PyGObject==3.42.1
PyJWT==2.3.0
pyparsing==2.4.7
pyproj==3.6.1
python-apt==2.4.0+ubuntu2
scikit-learn==1.3.2
scipy==1.11.3
SecretStorage==3.3.1
shapely==2.0.2
six==1.16.0
threadpoolctl==3.2.0
unattended-upgrades==0.1
wadllib==1.3.6
zipp==1.0.0
Removing intermediate container 851418d0d58d
 ---> 72361cb1e9fe
Successfully built 72361cb1e9fe
Successfully tagged example:latest
```

# 参考サイト

[How to Install Python 3.12 on Ubuntu 22.04](https://www.linuxtuto.com/how-to-install-python-3-12-on-ubuntu-22-04/)
[ubuntsuでpip installしたら「error: command 'x86_64-linux-gnu-gcc' failed with exit status 1」と出た](https://qiita.com/yuta_vamdemic/items/277a5a692840d06c4cd9)
[How To Install GDAL/OGR Packages on Ubuntu](https://mothergeo-py.readthedocs.io/en/latest/development/how-to/gdal-ubuntu-pkg.html)
[How To Install python3-mapnik on Ubuntu 22.04](https://installati.one/install-python3-mapnik-ubuntu-22-04/#google_vignette)
[How To Install python3-numpy on Ubuntu 22.04](https://installati.one/install-python3-numpy-ubuntu-22-04/)
[How To Install python3-shapely on Ubuntu 22.04](https://installati.one/install-fiona-ubuntu-22-04/)
[How To Install python3-sklearn on Ubuntu 22.04](https://installati.one/install-python3-sklearn-ubuntu-22-04/#google_vignette)
[How To Install "python3-fiona" Package on Ubuntu](https://zoomadmin.com/HowToInstall/UbuntuPackage/python3-fiona)