Alpine Linux ืืืืืฆืช ืืขืชืื ืงืจืืืืช ืืชืืื ืช ืืกืืก ืขืืืจ Docker. ื ืืืจ ืื ืฉืฉืืืืฉ ื-Alpine ืืืคืื ืืช ืืื ืืื ืฉืื ืืงืื ื ืืืชืจ ืืืช ืชืืืื ืืื ืืื ืฉืื ืืืืืจ ืืืชืจ.
ืืื ืื ืืชื ืืฉืชืืฉ ื-Alpine Linux ืขืืืจ ืืืฉืืื Python, ืื ืื:
- ืืืคื ืืช ืืื ืืื ืฉืื ืืื ืืจืื ืืืชืจ
- ืืืคื ืืช ืืชืืื ืืช ืฉืื ืืืืืืืช ืืืชืจ
- ืืืืื ืืช ืืืื
- ืืืกืืคื ืฉื ืืืจ ืื ืืืื ืืืจืื ืืฉืืืืืช ืืืื ืจืืฆื
ืืื ื ืืื ืืืืข ืืืืืฅ ืืืฉืชืืฉ ื-Alpine, ืื ืืืืข ืขืืืื ืื ืืืื ืืืฉืชืืฉ ืื ืขื Python.
ืืื ืื ืฉืื ืืืืืฆืื ืขื ืืืคืืื?
ืืืื ื ื ืื ืฉืื ืื ื ืฆืจืืืื gcc ืืืืง ืืืชืืื ื ืฉืื ื ืืื ืื ื ืจืืฆืื ืืืฉืืืช ืืช Alpine Linux ืืขืืืช Ubuntu 18.04 ืืืืื ืช ืืืืจืืช ืืื ืืื ืืืืื ืืชืืื ื ืืกืืคื.
ืจืืฉืืช, ืืื ื ืืจืื ืฉืชื ืชืืื ืืช ืื ืฉืืื ืืช ืืืืืื ืฉืืื:
$ docker pull --quiet ubuntu:18.04
docker.io/library/ubuntu:18.04
$ docker pull --quiet alpine
docker.io/library/alpine:latest
$ docker image ls ubuntu:18.04
REPOSITORY TAG IMAGE ID SIZE
ubuntu 18.04 ccc6e87d482b 64.2MB
$ docker image ls alpine
REPOSITORY TAG IMAGE ID SIZE
alpine latest e7d92cdc71fe 5.59MB
ืืคื ืฉืืชื ืืืื ืืจืืืช, ืชืืื ืช ืืืกืืก ืขืืืจ ืืืคืืื ืืื ืืจืื ืืืชืจ ืงืื ื. ืืขืช ื ื ืกื ืืืชืงืื gcc ืืืืชืืื ืขื ืืืืื ืื:
FROM ubuntu:18.04
RUN apt-get update &&
apt-get install --no-install-recommends -y gcc &&
apt-get clean && rm -rf /var/lib/apt/lists/*
ืืชืืืช ื-Dockerfile ืืืืฉืื ืืื ืืขืืจ ืืชืืื ืืืืืจ ืืื.
ืืืื ื ืืืื ืืช ืืืืจืืช ืืืจืืื:
$ time docker build -t ubuntu-gcc -f Dockerfile.ubuntu --quiet .
sha256:b6a3ee33acb83148cd273b0098f4c7eed01a82f47eeb8f5bec775c26d4fe4aae
real 0m29.251s
user 0m0.032s
sys 0m0.026s
$ docker image ls ubuntu-gcc
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu-gcc latest b6a3ee33acb8 9 seconds ago 150MB
ืื ื ืืืืจืื ืขื ืืืชื ืืืืจ ืขืืืจ Alpine (Dockerfile):
FROM alpine
RUN apk add --update gcc
ืื ื ืืจืืืืื, ืืกืชืืืื ืขื ืืืื ืืืืืื ืฉื ืืืืืื:
$ time docker build -t alpine-gcc -f Dockerfile.alpine --quiet .
sha256:efd626923c1478ccde67db28911ef90799710e5b8125cf4ebb2b2ca200ae1ac3
real 0m15.461s
user 0m0.026s
sys 0m0.024s
$ docker image ls alpine-gcc
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine-gcc latest efd626923c14 7 seconds ago 105MB
ืืคื ืฉืืืืื, ืชืืื ืืช ืืืืกืกืืช ืืืคืื ื ื ืืกืคืืช ืืืจ ืืืชืจ ืืื ืงืื ืืช ืืืชืจ: 15 ืฉื ืืืช ืืืงืื 30 ืืืืื ืืชืืื ื ืืื 105MB ืืขืืืช 150MB. ืื ืื ืืื!
ืืื ืื ื ืขืืืจ ืืื ืืืช ืืคืืืงืฆืืืช Python, ืื ืืื ืื ืื ืื ืืจืื.
ืชืืื ืช ืคืืืชืื
ืืืฉืืื Python ืืฉืชืืฉืื ืืขืชืื ืงืจืืืืช ืืคื ืืืช ืื-matplotlib. ืืื, ืืคืฉืจืืช ืืืช ืืื ืืงืืช ืืช ืืชืืื ื ืืจืฉืืืช ืืืืกืกืช ืืืืื ืืืืฆืขืืช Dockerfile ืื:
FROM python:3.8-slim
RUN pip install --no-cache-dir matplotlib pandas
ืืืื ื ืืกืืฃ ืืช ืื:
$ docker build -f Dockerfile.slim -t python-matpan.
Sending build context to Docker daemon 3.072kB
Step 1/2 : FROM python:3.8-slim
---> 036ea1506a85
Step 2/2 : RUN pip install --no-cache-dir matplotlib pandas
---> Running in 13739b2a0917
Collecting matplotlib
Downloading matplotlib-3.1.2-cp38-cp38-manylinux1_x86_64.whl (13.1 MB)
Collecting pandas
Downloading pandas-0.25.3-cp38-cp38-manylinux1_x86_64.whl (10.4 MB)
...
Successfully built b98b5dc06690
Successfully tagged python-matpan:latest
real 0m30.297s
user 0m0.043s
sys 0m0.020s
ืื ื ืืงืืืื ืชืืื ื ืืืืื 363MB.
ืืื ื ืฆืืื ืืืชืจ ืขื ืืืคืืื? ืืื ื ื ืกื:
FROM python:3.8-alpine
RUN pip install --no-cache-dir matplotlib pandas
$ docker build -t python-matpan-alpine -f Dockerfile.alpine .
Sending build context to Docker daemon 3.072kB
Step 1/2 : FROM python:3.8-alpine
---> a0ee0c90a0db
Step 2/2 : RUN pip install --no-cache-dir matplotlib pandas
---> Running in 6740adad3729
Collecting matplotlib
Downloading matplotlib-3.1.2.tar.gz (40.9 MB)
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/
tmp/pip-install-a3olrixa/matplotlib/setup.py'"'"'; __file__='"'"'/tmp/pip-install-a3olrixa/matplotlib/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-a3olrixa/matplotlib/pip-egg-info
...
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
The command '/bin/sh -c pip install matplotlib pandas' returned a non-zero code: 1
ืื ืงืืจื?
ืืืคืืื ืืื ื ืชืืื ืืืืืืื
ืื ืชืกืชืื ืขื ื-build, ืืืืืกืก ืขื ืืืืื, ืชืจืื ืฉืืื ืืืจืื ืืช matplotlib-3.1.2-cp38-cp38-manylinux1_x86_64.WHL.
ืื ืืื ืืจื ืืืืื. Alpine ืืืจืื ืืช ืืืงืืจืืช `matplotlib-3.1.2.tar.gz` ืืืืืื ืฉืืื ืืื ื ืชืืื ืืชืงื
ืืื? ืจืื ืืืคืฆืืช ืฉื ืืื ืืงืก ืืฉืชืืฉืืช ืืืจืกืช GNU (glibc) ืฉื ืืกืคืจืืื ืืกืื ืืจืืืช C, ืฉืืืขืฉื ื ืืจืฉืช ืืื ืชืืื ืืช ืฉื ืืชืืช ื-C, ืืืื Python. ืืื Alpine ืืฉืชืืฉ ื-'musl', ืืืืืืื ืฉืืงืืฆืื ืืืื ืืจืืื ืืืื ืืืืขืืื ื'glibc', ืื ืคืฉืื ืื ืืืคืฆืื.
ืืื, ืื ืืชื ืืฉืชืืฉ ื-Alpine, ืืชื ืฆืจืื ืืงืืคื ืืช ืื ืืงืื ืฉื ืืชื ื-C ืืื ืืืืืช Python.
ืื, ืื, ืชืฆืืจื ืืืคืฉ ืืช ืืจืฉืืื ืฉื ืื ืืชืืืช ืฉืืืื ืฉืฆืจืื ืืืจืืื ืืขืฆืื.
ืืืงืจื ืื ื ืงืื ืืช ืื:
FROM python:3.8-alpine
RUN apk --update add gcc build-base freetype-dev libpng-dev openblas-dev
RUN pip install --no-cache-dir matplotlib pandas
ืืืื ืืื ืืื ืืืงื...
... 25 ืืงืืช 57 ืฉื ืืืช! ืืืืื ืืชืืื ื ืืื 851MB.
ืชืืื ืืช ืืืืกืกืืช ืืืคืื ื ืืืงืืืช ืืจืื ืืืชืจ ืืื ืืื ืืช, ืื ืืืืืืช ืืืชืจ ืืืืืื, ืืขืืืื ืฆืจืื ืืืคืฉ ืืช ืื ืืชืืืช. ื ืืชื ืืืืื ืืืงืืื ืืช ืืืื ืืืจืืื ืืืืฆืขืืช
ืื ืื ืืื!
Alpine ืขืืื ืืืจืื ืืืืืื ืืืชื ืฆืคืืืื ืืืื ืจืืฆื
- ืืชืืืืจืื, musl ืชืืื ื-glibc, ืื ืืคืืขื ืืืืืืื ืืืืืื ืืืจืื ืืืขืืืช ืจืืืช. ืืื ืื, ืื ืจืื ืฉืื ืืืื ืื ื ืขืืืื. ืืืื ืืกืคืจ ืืขืืืช ืฉืขืืืืืช ืืืชืจืืฉ:
- ื-Alpine ืืฉ ืืืื ืขืจืืืช ืืืืื ืงืื ืืืชืจ ืืืจืืจืช ืืืื, ืื ืฉืืืื ืืืืืื
ืฉืืืืืช ื- Python - ืืืง ืืืืฉืชืืฉืื ืืฆืื ืืช ืื
ืืืฉืืื Python ืืืืืื ืืืชืจ ืืืื ืืืจื ืฉืื musl ืืงืฆื ืืืืจืื (ืฉืื ื ื-glibc). - ืืื ืืืฉืชืืฉืื
ื ืืฆื ืฉืืืื ืืขืช ืขืืฆืื ืืชืืจืื
ืืืื ืฉืืืืืช ืืื ืืืจ ืชืืงื ื, ืืื ืื ืืืืข ืืื ืขืื ืืืื.
ืื ืชืฉืชืืฉ ืืชืืื ืืช ืืืคืื ืืืช ืขืืืจ Python
ืื ืืื ื ืจืืฆื ืืืชืขืกืง ืืื ืืื ืืืืื ืืืจืืื, ืืืืคืืฉ ืืืจ ืชืืืช ืืฉืืืืืช ืคืืื ืฆืืืืืืช, ืื ืชืฉืชืืฉ ื-Alpine Linux ืืชืืื ืช ืืกืืก.
ืืงืืจ: www.habr.com