Alpine သည် Python အတွက် အဆ ၅၀ နှေးကွေးသော Docker တည်ဆောက်မှုများကို စုစည်းပြီး ပုံများသည် ၂ ဆ ပိုလေးသည်

Alpine သည် Python အတွက် အဆ ၅၀ နှေးကွေးသော Docker တည်ဆောက်မှုများကို စုစည်းပြီး ပုံများသည် ၂ ဆ ပိုလေးသည်

Alpine Linux ကို Docker အတွက် အခြေခံပုံအဖြစ် မကြာခဏ အကြံပြုထားသည်။ Alpine ကိုအသုံးပြုခြင်းဖြင့် သင်၏တည်ဆောက်မှုများကို သေးငယ်စေမည်ဖြစ်ပြီး သင်၏တည်ဆောက်မှုလုပ်ငန်းစဉ်ကို ပိုမိုမြန်ဆန်စေမည်ဖြစ်ကြောင်း သင့်အား ပြောကြားခဲ့ပါသည်။

သို့သော် အကယ်၍ သင်သည် Python အပလီကေးရှင်းများအတွက် Alpine Linux ကို အသုံးပြုပါက၊

  • မင်းရဲ့တည်ဆောက်မှုကို ပိုနှေးစေတယ်။
  • သင့်ပုံများကို ပိုကြီးစေသည်။
  • သင်၏အချိန်ကိုဖြုန်းတီးခြင်း။
  • အဆုံးတွင် ၎င်းသည် runtime တွင် အမှားအယွင်းများကို ဖြစ်စေနိုင်သည်။


Alpine ကို အဘယ်ကြောင့် အကြံပြုထားသည်ကို လေ့လာကြည့်ကြစို့၊ သို့သော် ၎င်းကို Python နှင့် အဘယ်ကြောင့် မသုံးသင့်သေးသနည်း။

လူတွေက Alpine ကို ဘာကြောင့် အကြံပေးကြတာလဲ။

ကျွန်ုပ်တို့၏ပုံ၏တစ်စိတ်တစ်ပိုင်းအနေဖြင့် 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

သင်မြင်ရသည့်အတိုင်း Alpine အတွက် အခြေခံပုံသည် များစွာသေးငယ်သည်။ အခု gcc ကို install လုပ်ပြီး Ubuntu နဲ့ စတင်လိုက်ရအောင်။

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

ကတိပြုထားသည့်အတိုင်း၊ Alpine-based ပုံများကို ပိုမိုမြန်ဆန်စွာ စုဆောင်းနိုင်သည်- 15 အစား 30 စက္ကန့်နှင့် ပုံအရွယ်အစားမှာ 105MB နှင့် 150MB ဖြစ်သည်။ တော်တော်ကောင်းပါတယ်။

ဒါပေမယ့် Python အက်ပလီကေးရှင်းကိုတည်ဆောက်ခြင်းသို့ပြောင်းပါက အရာအားလုံးသည် နှင်းဆီပန်းပွင့်မဟုတ်ပေ။

Python ပုံ

Python အပလီကေးရှင်းများသည် ပန်ဒါများနှင့် matplotlib ကို မကြာခဏ အသုံးပြုကြသည်။ ထို့ကြောင့်၊ ရွေးချယ်စရာတစ်ခုမှာ ဤ Dockerfile ကို အသုံးပြု၍ တရားဝင် Debian-based ရုပ်ပုံကို ယူရန်ဖြစ်သည်။

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 အရွယ်အစားရှိသော ရုပ်ပုံတစ်ပုံကို ရရှိသည်။
Alpine နဲ့ ပိုကောင်းအောင် လုပ်မှာလား။ ကြိုးစားကြည့်ရအောင်:

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

အဘယ်အရာကိုသွားမယ့်?

Alpine သည် ဘီးများကို မပံ့ပိုးပါ။

Debian ကိုအခြေခံထားသည့် build ကိုသင်ကြည့်ရှုပါက၊ ၎င်းသည် matplotlib-3.1.2-cp38-cp38-manylinux1_x86_64 ကိုဒေါင်းလုဒ်လုပ်နေသည်ကိုတွေ့ရပါမည်။whl.

၎င်းသည် ဘီးအတွက် ဒွိစုံတစ်ခုဖြစ်သည်။ Alpine သည် အရင်းအမြစ် `matplotlib-3.1.2.tar ကို ဒေါင်းလုဒ်လုပ်သည်။gz`စံနှုန်းကို မထောက်ထားဘူး။ ရထားဘီး.

အဘယ်ကြောင့်? Linux ဖြန့်ဖြူးမှုအများစုသည် C စံပြစာကြည့်တိုက်၏ GNU ဗားရှင်း (glibc) ကိုအသုံးပြုသည်၊ အမှန်မှာ Python အပါအဝင် C တွင်ရေးထားသောပရိုဂရမ်တိုင်းအတွက်လိုအပ်သည်။ သို့သော် Alpine သည် 'musl' ကိုအသုံးပြုပြီး ထို binaries များကို `glibc` အတွက် ဒီဇိုင်းထုတ်ထားသောကြောင့် ၎င်းတို့သည် ရွေးချယ်စရာတစ်ခုမဟုတ်ပေ။

ထို့ကြောင့်၊ အကယ်၍ သင်သည် Alpine ကိုအသုံးပြုပါက၊ Python package တစ်ခုစီတွင် C ဖြင့်ရေးထားသောကုဒ်အားလုံးကို compile လုပ်ရန်လိုအပ်သည်။

အိုး၊ ဟုတ်ကဲ့၊ သင်ကိုယ်တိုင် ပြုစုရန်လိုအပ်သော မှီခိုမှုစာရင်းကို သင်ရှာဖွေရမည်ဖြစ်ပါသည်။
ဤကိစ္စတွင်ကျွန်ုပ်တို့သည်ဤအရာကိုရရှိသည်။

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 ရှိပါတယ်။

အယ်လ်ပိုင်းအခြေခံပုံများ တည်ဆောက်ရန် အချိန်ပိုကြာသည်၊ ၎င်းတို့သည် အရွယ်အစားပိုကြီးပြီး မှီခိုမှုအားလုံးကို သင်ရှာဖွေရန် လိုအပ်သေးသည်။ အသုံးပြု၍ စုဝေးမှုအရွယ်အစားကို လျှော့ချနိုင်သည်။ multi-stage တည်ဆောက်မှုများ ဒါပေမယ့် ဆိုလိုတာက ဒီထက်ပိုပြီး အလုပ်တွေ လုပ်ဖို့လိုတယ်။

အဲဒါမဟုတ်ဘူး။

Alpine သည် runtime တွင် မမျှော်လင့်ထားသော bug များကို ဖြစ်စေနိုင်သည်။

သေချာတာကတော့ ဒီအမှားတွေကို ပြင်ပြီးပြီ၊ ဒါပေမယ့် နောက်ထပ် ဘယ်လောက်ရှိဦးမလဲ ဆိုတာ ဘယ်သူသိမလဲ။

Python အတွက် Alpine ပုံများကို မသုံးပါနှင့်

ကြီးမား၍ ရှည်လျားသော တည်ဆောက်မှုများ၊ မှီခိုမှုနှင့် ဖြစ်နိုင်ချေရှိသော အမှားအယွင်းများကို ရှာဖွေခြင်းမပြုလိုပါက Alpine Linux ကို အခြေခံပုံအဖြစ် မသုံးပါနှင့်။ အခြေခံပုံကောင်းကို ရွေးချယ်ပါ။.

source: www.habr.com

မှတ်ချက် Add