alpine linux 入門した

alpine linux 入門した

第9回 コンテナ型仮想化の情報交換会@福岡 http://ct-study.connpass.com/event/28449/ で発表したやつ

5664fe255c9690cb1b872e1ca21a8d78?s=128

yasuaki-tahira

April 23, 2016
Tweet

Transcript

  1. Alpine Linuxೖ໳ͨ͠ 2016/04/23 ୈ9ճ ίϯςφܕԾ૝Խͷ৘ใަ׵ձ GMO Pepabo, inc. λώϥ(@tap1ra)

  2. ࣗݾ঺հ > λώϥ(@tap1ra) > GMOϖύϘגࣜձࣾ ϗεςΟϯάࣄۀ෦ ɹΠϯϑϥνʔϜॴଐ ओʹϩϦϙοϓΛ୲౰ > ௼Γ෦

    > ΧϝχοΩ http://tapira.hatenablog.com/ > Χϝϊγϟγϯ https://kame.photos/
  3. Alpine Linuxͱ͸ʁ

  4. Alpine Linux Small. Simple. Secure. http://www.alpinelinux.org/ musl libc(※1) & busybox(※2)Ͱߏ੒͞Εͨ

    ηΩϡϦςΟࢦ޲ͷܰྔLinuxσΟετϦϏϡʔγϣϯ ※1 glibcޓ׵ͷܰྔCϥΠϒϥϦ ※2 `/bin/ls -> /bin/busybox`
  5. ࢖ͬͯΈΔ > ҎԼͷίϯςφΛ࡞੒ php-fpm ɹɹ 0.0.0.0:9000->9000/tcp php-fpm nginx ɹɹɹ 0.0.0.0:80->80/tcp

    nginx docker-mariadb-alpine 0.0.0.0:3306->3306/tcp maria ※ dockerfile ͸ҎԼࢀর͍ͩ͘͞ɻ
 https://github.com/yasuaki-tahira/docker/blob/master/alpine-wordpress/nginx.dockerfile
  6. wordpressಈ͍ͨʂ

  7. Alpine Linux࠷େͷಛ௃ ͸αΠζ͕খ͍͜͞ͱ

  8. ΠϝʔδαΠζ͸CentOSͷ1/40 [PMAC226S ~/work/Docker]$ docker images REPOSITORY TAG IMAGE ID CREATED

    SIZE centos latest 778a53015523 2 weeks ago 196.7 MB alpine latest d7a513a663c1 2 weeks ago 4.798 MB
  9. pull଎͍ [PMAC226S ~]$ time docker pull centos:latest latest: Pulling from

    library/centos real 1m41.977s user 0m0.060s sys 0m0.050s [PMAC226S ~]$ time docker pull alpine:latest latest: Pulling from library/alpine real 0m6.527s user 0m0.028s sys 0m0.021s
  10. build଎͍(pullͱಉ͡ཧ༝) [PMAC226S ~/work/Docker]$ cat alpine.dockerfile FROM alpine:latest CMD ["echo", “hoge"]

    [PMAC226S ~/work/Docker]$ time docker build -f alpine.dockerfile -t alpinetest . Successfully built e52bb6c909f1 real 0m4.089s user 0m0.021s sys 0m0.032s [PMAC226S ~/work/Docker]$ time docker build -f centos.dockerfile -t centostest . Successfully built 7aa9ba3ac6e9 real 0m50.189s user 0m0.050s sys 0m0.041s
  11. ଎͍ʂʂ

  12. ߴ଎ͰpullͱbuildͰ͖Δ Ҏ֎ͷڧΈΛߟ͑Δ

  13. base image͕खݩʹ͋Δ ঢ়ଶͰͷbuildͷࠩ͸ʁ

  14. ͜Μͳঢ়ଶ [PMAC226S ~/work/Docker]$ docker images REPOSITORY TAG IMAGE ID CREATED

    SIZE centos latest 778a53015523 2 weeks ago 196.7 MB alpine latest d7a513a663c1 2 weeks ago 4.798 MB
  15. alpineΛ࢖ͬͯbuild [PMAC226S ~/work/Docker/alpine]$ cat alpine.dockerfile FROM alpine:latest CMD ["echo", “hoge”]

    [PMAC226S ~/work/Docker/alpine]$ for i in `seq 1 100`; do cp alpine.dockerfile alpine.dockerfile$i; sed -i '' "s/hoge/hoge$i/" alpine.dockerfile$i; done [PMAC226S ~/work/Docker/alpine]$ time for i in `seq 1 100`; do docker build -f alpine.dockerfile$i -t alpinetest$i .; done real 0m25.245s user 0m2.172s sys 0m2.146s
  16. [PMAC226S ~/work/Docker/centos]$ cat centos.dockerfile FROM centos:latest CMD ["echo", "hoge"] [PMAC226S

    ~/work/Docker/centos]$ for i in `seq 1 100`; do cp centos.dockerfile centos.dockerfile$i; sed -i '' "s/hoge/hoge$i/" centos.dockerfile$i; done [PMAC226S ~/work/Docker/centos]$ time for i in `seq 1 100`; do docker build -f centos.dockerfile$i -t centostest$i .; done real 0m24.879s user 0m2.074s sys 0m2.048s CentOSΛ࢖ͬͯbuild
  17. ಉ͡ϕʔεΠϝʔδΛ࢖͏ ͷͰ͋Ε͹ɺؔ܎ͳͦ͞͏

  18. େྔʹίϯςφͷىಈˍऴྃ Λ܁Γฦ͢ඞཁ͕͋Δͱ͖͸ʁ

  19. echo͢Δ͚ͩͷίϯςφ1000ݸىಈ [PMAC226S ~/work/Docker]$ time for i in `seq 1 1000`;

    do docker run --rm centos echo hoge; done real 7m27.710s user 0m22.564s sys 0m10.174s [PMAC226S ~/work/Docker]$ time for i in `seq 1 1000`; do docker run --rm alpine echo hoge; done real 7m24.548s user 0m21.751s sys 0m10.052s
  20. ਺Λ૿΍ͯ͠࠶νϟϨϯδ [PMAC226S ~]$ time for i in `seq 1 10000`;

    do docker run --rm centos echo hoge; done real 71m49.987s user 4m1.459s sys 2m28.859s [PMAC226S ~]$ time for i in `seq 1 10000`; do docker run --rm alpine echo hoge; done real 73m40.196s user 4m12.156s sys 2m49.322s
  21. nginx͕ಈ͘؀ڥͩͬͨΒʁ $ time for i in `seq 8000 8030`; do

    docker run -d -p $i:80 --link php-fpm-hoge:php-fpm -v $(pwd)/mnt:/DATA centos-nginx; done real 0m9.685s user 0m0.480s sys 0m0.381s $ time for i in `seq 8000 8030`; do docker run -d -p $i:80 --link php-fpm-fuga:php-fpm -v $(pwd)/mnt:/DATA yasuaki-tahira/nginx; done real 0m9.580s user 0m0.477s sys 0m0.391s
  22. ϕʔεΠϝʔδ͕ܰྔ͔Ͳ͏͔ ͸ɺىಈ଎౓ʹӨڹ͠ͳͦ͏

  23. औಘࡁΈͷϕʔεΠϝʔδͱͷࠩ෼Λ ࢖͏৔߹ɺalpineͰ͋Δඞཁͳ͍Μ ͡ΌͶʁͱࢥ͍࢝Ίͨ

  24. ܰྔͰ͋Δ͜ͱͷڧΈ͸΍ͬͺΓɺ pull΍build͕ߴ଎Ͱ͋Δ͜ͱɻ Ͳ͏͍͏ͱ͜ΖͰ׆͖Δͷ͔ߟ͑Δ

  25. ᶃຖ೔࠷৽ͷOSΛ࢖ͬͯϏϧυͤ͞Δ લड़ͷ௨ΓɺҰ౓མͱ͖ͯͨ͠ϕʔεΠϝʔδ͔Βͷ ࠩ෼Ͱߟ͑ΔͱɺϕʔεΠϝʔδαΠζͷେখ͸༨Γ ؔ܎ͳͦ͞͏ɻ ·ͬߋͳ؀ڥ΁ɺϑϧͰΠϝʔδͷऔಘΛඞཁͱ͢Δ ؀ڥͰ͋Ε͹ɺϕʔεΠϝʔδͷখ͞͞͸ͦͷ··଎ ౓ʹܨ͕ΔͷͰ༗༻Ͱ͸ͳ͍͔ɻ ྫɿܧଓతσϓϩΠϝϯτ

  26. ৗʹ࠷৽ͷঢ়ଶΛอͯΔ ΞΫςΟϒ ΞΫςΟϒ ΞΫςΟϒ 4/24 A B ίʔυ ؅ཧγεςϜ ᶃελϯό

    Π΁ຖ೔࠷৽ͷ dockerfileΛ·͘ ᶄDockerfileΛ ݩʹbuild ςετπʔϧ ػೳཁ݅Λຬͨͯ͠ ͍Δ͔ຖ೔ςετ ελϯόΠ ελϯόΠ ελϯόΠ 4/23
  27. ᶄ։ൃ؀ڥͷdockerԽ ࠓͩͱvagrantͰ΍ͬͯͦ͏ͳ෦෼ɻ 2ͭ3ͭىಈͤ͞Δͱ։ൃϚγʔϯ͕ਏ͘ͳΔɻ ·ͨɺvagrant upʹֻ͕͔࣌ؒΔ͔ΒɺϦϙδτϦʹ࠷ ৽ͷঢ়ଶ͕͋ͬͯ΋ɺ໘౗ͯ͘͘͞ϩʔΧϧʹ࣋ͬͯ ΔౕΛͦͷ··࢖͍ͨ͘ͳΔɻ ͜Ε͕Ұ෼Ͱwebserver / lb

    / db / etc্ཱ͕ͪΔΑ͏ʹͳ Ε͹ɺৗʹ࠷৽ͷঢ়ଶΛؾܰʹ࢖͑ͦ͏
  28. ͋·Γࢥ͍͖ͭ·ͤΜͰͨ͠ɻ ͜͏͍͏༻్ʹ͍͍Μ͡Όͳ͍ʁΈ ͍ͨͳ࿩Λɺͥͻڭ͍͑ͯͩ͘͞ʂ

  29. ͻͱ·ͣ๻͸ݸਓͰ؅ཧ͍ͯ͠ΔWebαΠτ Λɺalpineϕʔεͷίϯςφʹஔ͖׵͑ͯɺ ྑ͍࢖͍Ͳ͜ΖΛ୳͍͖͍ͯͨ͠ͱࢥ͍·͢

  30. (͓·͚)ͦͷଞAlpine Linux Λ৮ͬͯؾ͍ͮͨ͜ͱ

  31. ᶃύοέʔδ؅ཧγεςϜapk͕dockerfileͰͷهड़ʹ ద͍ͯ͠Δͱࢥͬͨ > `—no-cache` ΩϟογϡΛ࢒ͣ͞ύοέʔδͷΠϯετʔϧ͕Ͱ͖Δɻ Alpine Linux 3.3͔Β௥Ճ͞Εͯɺ `rm -f

    /var/apk/cache/*` ͯͨ͠ ͷ͕ෆཁʹͳΓɺهड़͕؆ૉԽ > `—virtual` OSSϏϧυ͚࣌ͩඞཁͳύοέʔδͳͲΛ `apk add --virtual build-dependencies build-base curl` ͱຊΦϓγϣϯΛ࢖͍ʮbuild-dependenciesʯͱ͍͏໊લͰά ϧʔϓԽ͓ͯ͘͠ͱɺ `apk del --purge build-dependencies` Ͱ·ͱΊͯ࡟আͰ͖ͯศར
  32. ᶄbusybox͚ͩͩͱਏ͍ wget࢖͓͏ͱͨ͠Β৭ʑΦϓγϣϯແͯ͘ɺ݁ہGNU൛ΛೖΕͨΓ / # wget --help BusyBox v1.24.1 (2015-12-16 08:00:02

    GMT) multi-call binary. / # wget --no-check-certificate https://raw.githubusercontent.com/wp-cli/ builds/gh-pages/phar/wp-cli.phar wget: unrecognized option: no-check-certificate / # apk update / # apk add wget / # wget --help GNU Wget 1.17.1, a non-interactive network retriever. / # wget --no-check-certificate https://raw.githubusercontent.com/wp-cli/ builds/gh-pages/phar/wp-cli.phar 2016-04-17 09:52:18 (1.76 MB/s) - 'wp-cli.phar' saved [4039990/4039990]
  33. ᶅ݁ہଠͬͯ͠·͏ [PMAC226S ~/src/github.com/yasuaki-tahira/docker]$ docker images REPOSITORY TAG IMAGE ID CREATED

    SIZE nginx latest 4867e002c947 27 hours ago 21.21 MB php-fpm latest 30d7f9dd7f6e 27 hours ago 97.16 MB docker-mariadb-alpine latest 3dcfe623a72d 27 hours ago 183.7 MB ͨͱ͑͹php-fpmΛಈ͔͢Πϝʔδ͚ͩͰҰؾʹ100MBۙ͘ʹͳͬͯ͠·ͬͨɻ ͔ͤͬ͘ϕʔεΠϝʔδͷ͕ࠩCentOSͷ1/40ͩͬͨͷʹɺ࠷ऴతʹ࢖͑Δঢ়ଶͷΠ ϝʔδ͕100MBͱ300MBʹͳͬͨΓͯ͠ɺ΋͍ͬͨͳ͍ͳͱࢥͬͨʢ΋ͪΖΜখ͞ ͍ํ͕ྑ͍͚Ͳʣ খ͘͞࡞Ζ͏ͱҙࣝͯͯ͠΋ɺʮ͋Ε͕ͳ͍͜Ε͕ͳ͍ʯͱͳͬͯɺ౎౓ೖΕΔ ͷ͸େมͩͳʔͱࢥͬͨ
  34. ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠