alpine linux 入門した

alpine linux 入門した

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

5664fe255c9690cb1b872e1ca21a8d78?s=128

yasuaki-tahira

April 23, 2016
Tweet

Transcript

  1. 2.
  2. 4.

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

    ηΩϡϦςΟࢦ޲ͷܰྔLinuxσΟετϦϏϡʔγϣϯ ※1 glibcޓ׵ͷܰྔCϥΠϒϥϦ ※2 `/bin/ls -> /bin/busybox`
  3. 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
  4. 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
  5. 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
  6. 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
  7. 11.
  8. 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
  9. 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
  10. 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
  11. 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
  12. 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
  13. 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
  14. 26.

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

    Π΁ຖ೔࠷৽ͷ dockerfileΛ·͘ ᶄDockerfileΛ ݩʹbuild ςετπʔϧ ػೳཁ݅Λຬͨͯ͠ ͍Δ͔ຖ೔ςετ ελϯόΠ ελϯόΠ ελϯόΠ 4/23
  15. 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` Ͱ·ͱΊͯ࡟আͰ͖ͯศར
  16. 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]
  17. 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ʹͳͬͨΓͯ͠ɺ΋͍ͬͨͳ͍ͳͱࢥͬͨʢ΋ͪΖΜখ͞ ͍ํ͕ྑ͍͚Ͳʣ খ͘͞࡞Ζ͏ͱҙࣝͯͯ͠΋ɺʮ͋Ε͕ͳ͍͜Ε͕ͳ͍ʯͱͳͬͯɺ౎౓ೖΕΔ ͷ͸େมͩͳʔͱࢥͬͨ