Upgrade to Pro — share decks privately, control downloads, hide ads and more …

コマンド実行環境としてのDocker

hamaco
December 08, 2016

 コマンド実行環境としてのDocker

Fukuoka.php Vol.20で発表したDockerの話です。

hamaco

December 08, 2016
Tweet

More Decks by hamaco

Other Decks in Programming

Transcript

  1. Agenda • ͸͡Ίʹ • Docker ͱ͸ • Docker Image Λ࡞ͬͯΈΔ

    • ࠷খͷDocker ImageΛ໨ࢦͯ͠ • ·ͱΊ
  2. phan() { docker run -v $PWD:/mnt/src \ --rm -u "$(id

    -u):$(id -g)" \ cloudflare/phan:latest $@; return $?; }
  3. Docker ͱ͸ • Go ݴޠ • ίϯςφܕԾ૝Խ • LXC (Linux

    Container) • namespaces • cgroups
  4. DockerͷετϨʔδυϥΠό • AUFS (Docker for Mac / ެࣜεΫϦϓτ ) •

    DeviceMapper ( CentOS / Ubuntu ) • Btrfs • OverlayFS ( CoreOS / Barge ) • ZFS
  5. #01 جຊͷDocker Image FROM alpine:3.4 ENV PHP_VERSION 7.0.13 WORKDIR /tmp

    RUN apk add --no-cache --virtual .php-builddeps \ ca-certificates bash git patch re2c flex make gcc libc-dev RUN apk add --no-cache libxml2-dev bzip2-dev RUN git clone https://github.com/hnw/phpall.git RUN wget -O php-$PHP_VERSION.tar.gz \ http://jp2.php.net/get/php-$PHP_VERSION.tar.gz/from/this/mirror RUN /tmp/phpall/install-all-php.sh RUN mv /root/bin/php-$PHP_VERSION /root/bin/php RUN apk del .php-builddeps RUN rm -rf /tmp/php* ENTRYPOINT ["/root/bin/php"] CMD ["-v"]
  6. #01 جຊͷDocker Image RUN apk add --no-cache \ --virtual .php-builddeps

    \ ca-certificates bash git \ patch re2c flex make gcc libc-dev RUN apk add --no-cache \ libxml2-dev bzip2-dev
  7. #01 جຊͷDocker Image RUN git clone \ https://github.com/hnw/phpall.git RUN wget

    -O php-$PHP_VERSION.tar.gz \ http://jp2.php.net/get/php- $PHP_VERSION.tar.gz/from/this/mirror RUN /tmp/phpall/install-all-php.sh RUN mv /root/bin/php-$PHP_VERSION /root/bin/ php
  8. #02 RUNΛ1ͭʹ·ͱΊΔ FROM alpine:3.4 ENV PHP_VERSION 7.0.13 WORKDIR /tmp RUN

    apk add --no-cache --virtual .php-builddeps \ ca-certificates bash git patch re2c flex make gcc libc-dev \ && apk add --no-cache libxml2-dev bzip2-dev \ && git clone https://github.com/hnw/phpall.git \ && wget -O php-$PHP_VERSION.tar.gz \ http://jp2.php.net/get/php-$PHP_VERSION.tar.gz/from/this/mirror \ && /tmp/phpall/install-all-php.sh \ && mv /root/bin/php-$PHP_VERSION /root/bin/php \ && apk del .php-builddeps \ && rm -rf /tmp/php* ENTRYPOINT ["/root/bin/php"] CMD ["-v"]
  9. #03 ϕʔεΠϝʔδ FROM alpine:3.4 WORKDIR /work RUN apk add --no-cache

    --virtual .php-builddeps \ ca-certificates bash git make \ gcc patch re2c flex libc-dev \ && apk add --no-cache libxml2-dev bzip2-dev \ && git clone https://github.com/hnw/phpall.git
  10. #03 PHPΠϝʔδ FROM hamaco/fukuoka-php-20:03-base ENV PHP_VERSION 7.0.13 WORKDIR /work RUN

    wget -O php-$PHP_VERSION.tar.bz2 \ http://jp2.php.net/get/php-$PHP_VERSION.tar.bz2/from/this/mirror \ && /work/phpall/install-all-php.sh \ && mv /root/bin/php-$PHP_VERSION /root/bin/php \ && apk del .php-builddeps \ && rm -rf /work ENTRYPOINT ["/root/bin/php"] CMD ["-v"]
  11. #04 Ϗϧυ༻Πϝʔδ FROM alpine:3.4 ADD ./scripts/make-image.bash /work/make-image.bash WORKDIR /work RUN

    apk add --no-cache \ ca-certificates bash git make gcc patch re2c \ flex libc-dev libxml2-dev bzip2-dev \ && git clone https://github.com/hnw/phpall.git ENTRYPOINT ["/work/make-image.bash"]
  12. #04 ϏϧυεΫϦϓτ #!/usr/bin/env bash basedir=/work/images mkdir -p $basedir/etc/apk/ $basedir/root/bin/ cp

    /etc/apk/repositories $basedir/etc/apk/repositories { apk add --no-cache --root "$basedir" \ --keys-dir /etc/apk/keys --initdb libxml2-dev bzip2-dev cd /work/ wget -O php-7.0.13.tar.bz2 \ http://jp2.php.net/get/php-7.0.13.tar.bz2/from/this/mirror /work/phpall/install-all-php.sh cp /root/bin/php-7.0.13 $basedir/root/bin/php } >&2 tar czf images.tar.gz . -C "$basedir" && cat images.tar.gz
  13. #04 Ϗϧυ࣮ߦ $ docker build \ -t hamaco/fukuoka-php-20:04-base base $

    docker run --rm \ hamaco/fukuoka-php-20:04-base \ > images.tar.gz
  14. #06 PHPʹඞཁͳϑΝΠϧ # ldd /root/bin/php /lib/ld-musl-x86_64.so.1 (0x55733b8c7000) libbz2.so.1 => /usr/lib/libbz2.so.1

    (0x7f462d436000) libz.so.1 => /lib/libz.so.1 (0x7f462d220000) libxml2.so.2 => /usr/lib/libxml2.so.2 (0x7f462cef5000) libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x55733b8c7000)
  15. #06 ඞཁͳϑΝΠϧίϐʔ $ tree docker-image/ docker-image/ !"" lib # !""

    ld-musl-x86_64.so.1 # %"" libz.so.1 !"" root # %"" bin # %"" php %"" usr %"" lib !"" libbz2.so.1 %"" libxml2.so.2
  16. #06 docker import $ cd docker-image $ tar -c .

    | docker import - \ hamaco/fukuoka-php-20:06