kb84tkhrのブログ

何を書こうか考え中です あ、あと組織とは関係ないってやつです 個人的なやつ

Dockerのお勉強 - alpine-python3

Alpine Linuxにpython3を入れたイメージがfrolvlad/alpine-python3にあるので試してみる
パッケージから入れたpython3は3.6.6だったけどこっちはどうかな

DockerHubで見るとDockerfileが見える

FROM alpine:3.8
    
RUN apk add --no-cache python3 && \
    python3 -m ensurepip && \
    rm -r /usr/lib/python*/ensurepip && \
    pip3 install --upgrade pip setuptools && \
    if [ ! -e /usr/bin/pip ]; then ln -s pip3 /usr/bin/pip ; fi && \
    if [[ ! -e /usr/bin/python ]]; then ln -sf /usr/bin/python3 /usr/bin/python; fi && \
    rm -r /root/.cache

apkで入れてる、ということはやっぱり3.6.6か
意外と大したことをしてるわけじゃなかった
でも自分でイメージ作りたいときの参考になるな

イメージを持ってくる

$ docker pull frolvlad/alpine-python3
$ docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
frolvlad/alpine-python3   latest              cf6d1297856f        8 weeks ago         54.3MB

Alpineが5MBでPythonが50MBか
バッテリーが大きすぎませんかー

動かす

$ docker run --rm -it frolvlad/alpine-python3
/ # python3/ # python3
Python 3.6.6 (default, Aug 24 2018, 05:04:18)
[GCC 6.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello, world!")
Hello, world!

当然動くとしてやっぱり3.6.6

pipも試す

/ # pip install requests
Collecting requests
  Downloading https://files.pythonhosted.org/packages/7d/e3/20f3d364d6c8e5d2353c72a67778eb189176f08e873c9900e10c0287b84b/requests-2.21.0-py2.py3-none-any.whl (57kB)
    100% |████████████████████████████████| 61kB 2.5MB/s
    :
    :
Collecting idna<2.9,>=2.5 (from requests)
  Downloading https://files.pythonhosted.org/packages/14/2c/cd551d81dbe15200be1cf41cd03869a46fe7226e7450af7a6545bfc474c9/idna-2.8-py2.py3-none-any.whl (58kB)
    100% |████████████████████████████████| 61kB 10.2MB/s
Installing collected packages: chardet, urllib3, certifi, idna, requests
Successfully installed certifi-2018.11.29 chardet-3.0.4 idna-2.8 requests-2.21.0 urllib3-1.24.1
/ # python3
>>> import requests
>>> res = requests.get("http://www.google.com")
>>> print(res.text)
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head>
  :
  :

いけた
とりあえずこれでいいか