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

docker-compose patterns 201603

docker-compose patterns 201603

Docker Meetup Tokyo #6 で、2016年 3月現在の docker や docker-compose の使い方をまとめて LT してみた資料です。

ryo nakamaru

March 05, 2016
Tweet

More Decks by ryo nakamaru

Other Decks in Technology

Transcript

  1.  +"846( ίϯςφࢧ෦ º $-* ઐ໳ࢧ෦  "NB[PO &$4 

    &$3 ϋϯζΦϯ  Ր ʙ!/)/ςίϥεגࣜձࣾ͞Μ !KBXTVHDPOUBJOFS
  2. // Nginx, Apache ͳͲͷ Web αʔό web: image: nginx ports:

    - "80:80" volumes: - "./content:/usr/share/nginx/html" // MySQL, PostgreSQL ͳͲͷ DB αʔό db: image: mysql:5.7 ports: - "3306:3306" volumes: - "./init-scripts:/docker-entrypoint-initdb.d" environment: - MYSQL_ROOT_PASSWORD - MYSQL_DATABASE - MYSQL_USER - MYSQL_PASSWORD // Redis, Memcached ͳͲͷΩϟογϡαʔό cache: image: redis ports: - "6379:6379" // ͳͲͳͲ..
  3. w αʔϏεతʹศརͳىಈ࣌Φϓγϣϯ w SFTUBSUίϯςφʹ෮׆ͷຐ๏͕͔͔Δɻͨͩ͠ϦεΫ΋͋Δɾɾ w MPHESJWFSศརͳϩάυϥΠόʔ͕૿͑·ͨ͠ʂ w OFUEPDLFSDPNQPTFͱͷ૊Έ߹Θͤൈ܈ w ߟྀ͢΂͖ϙΠϯτ

    w όΠφϦʗιʔείʔυ͸SVOWʁ%PDLFSpMF"%%  w ͪͳΈʹฐࣾ͸%PDLFSΒ͠͞Λੜ͔ͯ͠ w ։ൃத͸ιʔείʔυΛϚ΢ϯτ w ςετʗධՁʗຊ൪؀ڥ͸%PDLFSΠϝʔδʹࠝแ w σϓϩΠΛߟ͑Δͱɺ΍͸Γ%PDLFSJNBHF͸খ͘͢͞΂͖ w "MQJOF-JOVYਆʢ͚ͲNVTMMJCDɾɾʣ w ຊ֨తʹӡ༻͠Α͏ͱ͢Δͱͦͷଞࢮ͵΄Ͳ͍Ζ͍Ζ
  4. // ఆ࣌όονॲཧ batch: image: someones/cool-image:batch environment: - CRON="5 0 *

    * *" - MYSQL_DATABASE - MYSQL_USER - MYSQL_PASSWORD // CI ςετ test: image: someones/cool-image:test command: go test ./... volumes: - INTERVAL=1d - REPOSITORY=github.com/your/project working_dir: /go/src/github.com/your/project // ϩάసૹʢਂ෵ͳཧ༝ͰϑΥϫʔμʔͰ͸ͳ͍έʔεʣ fluentd: image: fluent/fluentd volumes: - "/path/to/dir:/fluentd/etc:ro" - "/var/log:/var/log/" environment: - FLUENTD_CONF=my.conf // ͳͲͳͲ..
  5. σʔλ ϘϦϡʔϜ ίϯςφʔ data volume containers γϯϓϧʹϗετͷσΟϨΫτϦΛϚ΢ϯτ͢Δͷͱ͸ҧ͍ɺ ؒʹઐ༻ͷίϯςφΛڬΉ͜ͱͰʜ ɾෳ਺ͷίϯςφ͔ΒϦΞϧλΠϜʹಉ͡ϑΝΠϧΛࢀরՄೳ ɾαʔϏείϯςφ͕ഁغ͞ΕͨޙͰ΋όοΫΞοϓ΍ϦετΞ͕؆୯

    IPTUNBDIJOF NZTRM DPOUBJOFS EBUBWPMVNF DPOUBJOFS   FH.Z42- WPMVNFTGSPN W WPMVNF IPTUpMFTZTUFN $ docker create --name data \ -v /var/lib/mysql busybox $ docker run -p 3306:3306 \ --volumes-from data mysql:5.7
  6. version: "2" services: // Data volume container dvc: image: "busybox"

    volumes: - /var/lib/mysql // Data volume container Λ࢖ͬͨ MySQL db1: image: mysql:5.7 ports: - "3306:3306" volumes_from: - dvc // ϗετϚγϯ͔Β௚઀Ϛ΢ϯτ͍ͯ͠Δ MySQL db2: image: mysql:5.7 ports: - "3307:3306" volumes: - "mysql-data:/var/lib/mysql" volumes: mysql-data:
  7. # e.g. docker-compose run build idea: image: pottava/gradle:2.9 command: idea

    volumes: - "./app:/app" volumes_from: - caches idea-fix: image: busybox command: sed -i -e "s/\/root\/\.gradle\/caches/\.\.\/caches/g" /app/project.iml volumes: - "./app:/app" build: image: pottava/gradle:2.9 command: build volumes: - "./app:/app" volumes_from: - caches caches: image: busybox volumes: - "./caches:/root/.gradle/caches" clean: image: pottava/gradle:2.9 command: clean volumes: - "./app:/app"
  8. w Α͘ݟΔͷ͸BMJBTʹઃఆͯ͠͠·͏ྫ ɹFH BMJBTBXTEPDLFSSVOSNW)0.&BXTSPPUBXTQPUUBWBBXTDMJ w 1*%ΦϓγϣϯʢEPDLFSSVOQJElIPTUʣΛ࢖͏ͱ ɹ͜Μͳ͜ͱ΋Ͱ͖ΔʂʢެࣜυΩϡϝϯτ΄΅ͦͷ··ɾɾʣ DBU&0'%PDLFSpMF '30.BMQJOF 36/BQLBEEOPDBDIFIUPQ

    $.%<lIUPQz> &0' EPDLFSCVJMEUNZIUPQ EPDLFSSVOJUSNQJEIPTUNZIUPQ w $PSF04ͳͲ%PDLFSલఏͷ04ͷ৔߹ɺ͜ͷύλʔϯ͸ͱͯ΋ศརɻ ɹπʔϧ͕%PDLFSJ[F͞Ε͍ͯΕ͹͢΂ͯίϯςφͰ׬݁Ͱ͖Δɻ
  9. εΫϦϓτࢼߦࡨޡ ύλʔϯ shell scripts pattern ίϯςφ͸ͱʹ͔͘ىಈɾഁغ͕௒଎ɻDPNNJUͰঢ়ଶͷอଘ΍࠶։΋؆୯ɻ γΣϧεΫϦϓτΛτϥΠΞϯυΤϥʔͰࢼ͢؀ڥͱͯ͠࠷దʂ "OTJCMFͳͲߏ੒؅ཧεΫϦϓτΛ࡞ͬͨΓɺ%PDLFSpMFΛ࡞ͬͨΓɾɾ ZPVSDPNQVUFS DFOUPTDPOUBJOFS

    FH$FOU04 $ docker run -it centos:6 bash [root /]# yum install -y ruby [root /]# exit $ ID=`docker ps -alq` $ docker commit $ID mine/ruby $ docker run -it mine/ruby bash [root /]# ruby -v [root /]# .. NJOFSVCZDPOUBJOFS
  10. $BTF" CJUOBNJXPSEQSFTT DPOUBJOFS   $BTF# OHJOY DPOUBJOFS XPSEQSFTT DPOUBJOFS

    NBSJBEC DPOUBJOFS   proxy: image: nginx ports: - "443:443" volumes: - “./nginx.conf:/etc/nginx/nginx.conf:ro“ links: - wp:upstream wp: image: wordpress links: - db:mysql db: image: mariadb:10.1 environment: MYSQL_ROOT_PASSWORD: foo wp: image: bitnami/wordpress ports: - "443:443"
  11. $BTF" CJUOBNJXPSEQSFTT DPOUBJOFS   ɾγϯϓϧͰ࢖͍΍ͦ͢͏ ɾ֤Ϟδϡʔϧ୯ҐͰ؅ཧ͠΍͍͢ ɾOHJOY͚ͩόʔδϣϯΞοϓʗઃఆมߋ ɾXPSEQSFTT͚ͩεέʔϧ ɾNBSJBECΛNZTRMʹஔ͖׵͑

    ɾؔ৺͕෼཭͞Ε͍ͯΔ ɾIUUQ ੩తϑΝΠϧΩϟογϡOHJOY ɾCBDLVQSFTUPSFNBSJBEC ɾʢ͜ͷྫ͸ඍົ͚ͩͲʣՄ༻ੑΛߴΊΒΕΔ ɾ%#͕ࢮΜͰ΋ιʔϦʔϖʔδ͸ͩͤΔ $BTF# OHJOY DPOUBJOFS XPSEQSFTT DPOUBJOFS NBSJBEC DPOUBJOFS