Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
docker-compose patterns 201603
Search
ryo nakamaru
March 05, 2016
Technology
16
3.3k
docker-compose patterns 201603
Docker Meetup Tokyo #6 で、2016年 3月現在の docker や docker-compose の使い方をまとめて LT してみた資料です。
ryo nakamaru
March 05, 2016
Tweet
Share
More Decks by ryo nakamaru
See All by ryo nakamaru
AWSで楽をするサービスメッシュ入門/appmesh-trial
pottava
1
1.4k
reinforce-2019-recap-lt
pottava
2
4.1k
ScaleShift-jp-2019-summer
pottava
1
190
Firecracker とは何か/what is Firecracker
pottava
13
5.3k
ハイブリッド並列 on Kubernetes/hybrid-parallel-program-on-kubernetes
pottava
1
410
AWS Fargate + Code 兄弟で始める継続的デリバリー / Continuous Delivery with AWS Fargate and Code brothers
pottava
12
3.1k
Singularity と NVIDIA GPU Cloud で作る ハイブリッド機械学習環境の構築 / Building a hybrid environment for Machine Learning with Singularity and NGC
pottava
3
1.2k
明日から始めるちょい足し λ / get-started-with-aws-lambda
pottava
4
2.4k
NGC と Singularity によるハイブリッド機械学習環境 / A hybrid environment for Machine Learning with NGC and Singularity
pottava
0
460
Other Decks in Technology
See All in Technology
オプトインカメラ:UWB測位を応用したオプトイン型のカメラ計測
matthewlujp
0
180
普通のエンジニアがLaravelコアチームメンバーになるまで
avosalmon
0
110
GitHub Copilot のテクニック集/GitHub Copilot Techniques
rayuron
37
14k
Amazon Kendra GenAI Index 登場でどう変わる? 評価から学ぶ最適なRAG構成
naoki_0531
0
110
組織に自動テストを書く文化を根付かせる戦略(2024冬版) / Building Automated Test Culture 2024 Winter Edition
twada
PRO
17
4.6k
KubeCon NA 2024 Recap: How to Move from Ingress to Gateway API with Minimal Hassle
ysakotch
0
210
ガバメントクラウドのセキュリティ対策事例について
fujisawaryohei
0
560
プロダクト開発を加速させるためのQA文化の築き方 / How to build QA culture to accelerate product development
mii3king
1
270
1等無人航空機操縦士一発試験 合格までの道のり ドローンミートアップ@大阪 2024/12/18
excdinc
0
160
LINEヤフーのフロントエンド組織・体制の紹介【24年12月】
lycorp_recruit_jp
0
530
大幅アップデートされたRagas v0.2をキャッチアップ
os1ma
2
540
Snykで始めるセキュリティ担当者とSREと開発者が楽になる脆弱性対応 / Getting started with Snyk Vulnerability Response
yamaguchitk333
2
190
Featured
See All Featured
How GitHub (no longer) Works
holman
311
140k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Thoughts on Productivity
jonyablonski
67
4.4k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
The World Runs on Bad Software
bkeepers
PRO
65
11k
The Language of Interfaces
destraynor
154
24k
The Pragmatic Product Professional
lauravandoore
32
6.3k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
Unsuck your backbone
ammeep
669
57k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Transcript
Docker Meetup Tokyo #6 docker-compose patterns
@pottava தؙ ྑ 461*/'*OD $PNQMFUFE %PDLFS"ENJOJTUSBUJPOBOE0QFSBUJPOT "84$FSUJpFE 4" %FW0QT&OHJOFFS1SP
தؙ ྑ "VUPNBUFECVJME EPDLFSSVO
தؙ ྑ "VUPNBUFE CVJME
ձࣾʢ461*/'εϐϯϑʣͰ %PDLFSΫϥελͰෳλΠτϧຊ൪ӡ༻தʂ ։ൃςετͪΖΜͯ͢%PDLFS
+"846( ίϯςφࢧ෦ º $-* ઐࢧ෦ "NB[PO &$4
&$3 ϋϯζΦϯ Ր ʙ!/)/ςίϥεגࣜձࣾ͞Μ !KBXTVHDPOUBJOFS
patterns
͍ΖΜͳίϯςφͷ͍ํ5JQTΛ EPDLFSDPNQPTFZNMͰ·ͱΊͯΈ·ͨ͠
ίϯςφͷ͍ํΛཧ͢Δͱ͖ʹ Կ͔ͷ͓ʹཱͯͱɾɾ
·ͣ
docker
docker patterns [ جຊܗ ]
αʔϏε ίϯςφʔ* service containers ίϯςφͷׂΛྨ͢ΔͨΊͷศٓతͳ୯ޠͰ͢
αʔϏε ίϯςφʔ service containers ੈͷதͷେ͖ͬͱ͜Εɻ ֎෦͔ΒͷϦΫΤετʹԠ͢Δ͜ͱΛظ͞Ε͍ͯΔɻ ଟ͘ͷ߹ϙʔτύϒϦογϡ͞ΕɺՔಇ͠ଓ͚Δͣͷίϯςφɻ IPTUNBDIJOF NZTRM DPOUBJOFS
NZTRM DPOUBJOFS NZTRM DPOUBJOFS FH.Z42- ZPVSDPNQVUFS .Z42-DMJFOU
// 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" // ͳͲͳͲ..
w αʔϏεతʹศརͳىಈ࣌Φϓγϣϯ w SFTUBSUίϯςφʹ෮׆ͷຐ๏͕͔͔Δɻͨͩ͠ϦεΫ͋Δɾɾ w MPHESJWFSศརͳϩάυϥΠόʔ͕૿͑·ͨ͠ʂ w OFUEPDLFSDPNQPTFͱͷΈ߹Θͤൈ܈ w ߟྀ͖͢ϙΠϯτ
w όΠφϦʗιʔείʔυSVOWʁ%PDLFSpMF"%% w ͪͳΈʹฐࣾ%PDLFSΒ͠͞Λੜ͔ͯ͠ w ։ൃதιʔείʔυΛϚϯτ w ςετʗධՁʗຊ൪ڥ%PDLFSΠϝʔδʹࠝแ w σϓϩΠΛߟ͑ΔͱɺΓ%PDLFSJNBHFখ͖͘͢͞ w "MQJOF-JOVYਆʢ͚ͲNVTMMJCDɾɾʣ w ຊ֨తʹӡ༻͠Α͏ͱ͢Δͱͦͷଞࢮ͵΄Ͳ͍Ζ͍Ζ
δϣϒ ίϯςφʔ* job containers ίϯςφͷׂΛྨ͢ΔͨΊͷศٓతͳ୯ޠͰ͢
δϣϒ ίϯςφʔ job containers DSPOͷΑ͏ʹཪͰͦͦ͜͜ؤு͍ͬͯΔίϯςφɻ ։ൃɾӡ༻ͷݱʹ࣋ͪࠐΉͳΒ͜ͷ͔Β࢝ΊΔͱ͍͍͔͠Εͳ͍ɻ ఆ࣌όονॲཧɺ$*ςετɺʢϩάυϥΠόΛͳ͔ͥΘͳ͍ʣϩάཧͳͲ IPTUNBDIJOF UPNDBU DPOUBJOFS
NZTRM DPOUBJOFS qVFOUqVFOUE DPOUBJOFS FH'MVFOUEʢࠓͬΆ͘ͳ͍͚ͲϚϯτͨ͠ϩάϑΥϧμΛࢹʣ "NB[PO $MPVE8BUDI-PHT &MBTUJDTFBSDI
// ఆ࣌όονॲཧ 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 // ͳͲͳͲ..
w ͠όονॲཧʹႈੑ͕͋ΔͳΒɺίϯςφಋೖʹ͍ͬͯ͜ w ͦͷଞϙʔτΛެ։ͤͣɺҰ࣌తʹམ͍͍ͪͯαʔϏε͍ͯΔ w ϗετͷϦιʔεΛޮՌతʹ͏Α͏؆୯ʹεέʔϧͰ͖Δ w FH EPDLFSDPNQPTFTDBMFCBUDI
σʔλ ϘϦϡʔϜ ίϯςφʔ data volume containers
σʔλ ϘϦϡʔϜ ίϯςφʔ 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
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:
docker patterns [ ࢧԉܥ ]
αΠυΧʔύλʔϯ sidecar pattern
EBUBWPMVNF DPOUBJOFS αΠυΧʔ ύλʔϯ sidecar pattern ͢Ͱʹଘࡏ͢ΔྡͷίϯςφΛ֦ு͠ɺڧԽ͢ΔͨΊͷͷɻ ͜ΕͰΞϓϦέʔγϣϯଆࣗͷؔ৺ͷΈʹूதͰ͖Δ͠ɺ αΠυΧʔଆͲΜͳΞϓϦέʔγϣϯʹͰ͍·ΘͤΔ෦ʹͳΕΔɻ IPTUNBDIJOF
OPEFKTTMJN DPOUBJOFS FHϦϙδτϦͷߋ৽ TPNFHJUTZOD DPOUBJOFS WPMVNFTGSPN WPMVNFTGSPN
w EPDLFSDPO͓͢͢Ίಈը 5IFEJTUSJCVUFETZTUFNUPPMLJU$POUBJOFSQBUUFSOTGPSNPEVMBSEJTUSJCVUFETZTUFNEFTJHO 1SFTFOUFECZ#SFOEBO#VSOT 4PGUXBSF&OHJOFFS (PPHMF IUUQTZPVUVCF1IUK*U UNT
Ξϯόαμʔύλʔϯ ambassador pattern
Ξϯόαμʔ ύλʔϯ ambassador pattern αʔϏείϯςφͱಉ͡ωοτϫʔΫωʔϜεϖʔεʹ͋ΔίϯςφͰ Ͳ͔͜ผͷͱ͜ΖͰಈ͘αʔϏεͷϓϥϛϯάʢαʔϏεΛݟ͚ͭɺ ܨ͛ɺෛՙࢄʣΛͯ͘͠ΕΔͷ͕Ξϯόαμʔɻ εέʔϧ͢Δʹඞਢͷύλʔϯɻ IPTUNBDIJOF QIQ
DPOUBJOFS [BQJFSUXFNQSPYZ DPOUBJOFS FHUXFNQSPYZ NFNDBDIFE NFNDBDIFE MPDBMIPTU
w SF*OWFOU͓͢͢Ίࢿྉ 'SPN-PDBM%PDLFS%FWFMPQNFOUUP1SPEVDUJPO%FQMPZNFOUz 1SFTFOUFECZ+ÉSÔNF1FUB[[POJ %PDLFS*OD IUUQXXXTMJEFTIBSFOFUSZPOBLBNBSVGSPNEFWUPQSPEBXTSFJOWFOU
Ξμϓλʔύλʔϯ adapter pattern
Ξμϓλʔ ύλʔϯ adapter pattern αʔϏείϯςφͷΠϯλʔϑΣΠεΛ౷Ұ͢ΔͨΊͷίϯςφɻ ͜ΕʹΑΓɺϞχλϦϯάͳͲ֎͔ΒͷϦΫΤετʹରͯ͠ αʔϏείϯςφͷதʹΑΒͣɺಉ͡ΠϯλʔϑΣΠεͰԠͰ͖Δɻ IPTUNBDIJOF SFEJTBMQJOF DPOUBJOFS
GPPSFEJTFYQPSUFS DPOUBJOFS FH3FEJTFYQPSUFS NVOJO /BHJPT MPDBMIPTU
ࢹɾཧίϯςφʔ monitoring containers
ཧɾࢹ ίϯςφʔ monitoring containers %PDLFSίϯςφͷঢ়ଶΛѲͨ͠ΓɺͦͷϝτϦΫεΛऩूͨ͠Γ ίϯςφ͕ಈ͘ϗετͷϝτϦΫεΛऩूͨ͠Γ͢Δίϯςφɻ %PDLFSͷιέοτΛίϯςφʹ͢ͷଟ͍ɻ IPTUNBDIJOF EKBOHP DPOUBJOFS
QPTUHSFT DPOUBJOFS HPPHMFDBEWJTPS DPOUBJOFS FHD"EWJTPS *OqVY%# (SBGBOB
w %BUB%PH.BDLFSFMͳͲಉ͡ΈͰΤʔδΣϯτ͕ ɹϝτϦΫεΛσʔλऩूαʔόʹૹ৴͍ͯ͠Δɻ w ͨͩϝτϦΫεΛ֎෦ʹૹ৴͢ΔλΠϓͱɺTXBSN&$4BHFOUͷ ɹΑ͏ʹͦͷϗετͷίϯςφΛཧ͢ΔλΠϓ͕͋Δɻ
docker patterns [ ςϯϙϥϦܥ ]
୯ൃίϚϯυύλʔϯ one-off commands pattern
୯ൃίϚϯυύλʔϯ one-off commands pattern ϗετʹΠϯετʔϧ͞Ε͍ͯͳ͍ϛυϧΣΞ$-*πʔϧΛͬͯ ϗετ্ͷϑΝΠϧ֎෦ϦιʔεʹӨڹΛ༩͑Δίϯςφɻ ϗετΛΫϦʔϯʹอͯɺπʔϧͷෳόʔδϣϯར༻༰қʹͳΔɻ ZPVSDPNQVUFSXJUIPVU+BWB FH(SBEMF WPMVNF
CVJME $ docker create --name cache \ -v /root/.gradle/caches \ busybox $ docker run --rm \ -v `pwd`/app:/app \ --volumes-from cache \ pottava/gradle:2.9 \ build HSBEMFDPNNBOEDPOUBJOFS
# 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"
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͞Ε͍ͯΕͯ͢ίϯςφͰ݁Ͱ͖Δɻ
εΫϦϓτࢼߦࡨޡύλʔϯ shell scripts pattern
εΫϦϓτࢼߦࡨޡ ύλʔϯ 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
docker patterns [ ಛघ ]
ωοτϫʔΫίϯςφʔ* networking containers ίϯςφͷׂΛྨ͢ΔͨΊͷศٓతͳ୯ޠͰ͢
ωοτϫʔΫ ίϯςφʔ networking containers ෳίϯςφͰωοτϫʔΫΠϯλʔϑΣΠεΛڞ༗͢ΔͨΊͷίϯςφɻ ωοτϫʔΫίϯςφʹܨ͕ͬͨίϯςφ͓ޓ͍MPDBMIPTUͰ௨৴͕Մೳɻ ϗετϚγϯͰϙʔτͷڝ߹͕ى͖ͳ͍ͷͰɺ։ൃதศརͳ͜ͱɻ IPTUNBDIJOF
OHJOY DPOUBJOFS OFUXPSLJOHDPOUBJOFS OHJOY DPOUBJOFS FH"QBDIF ZPVSDPNQVUFS #SPXTFS IUUQ IUUQ
EPDLFSฤ ͓ΘΓ
ͯ͞ɺͬͱ
docker-compose
docker-compose ?
খׂ͘͞͞ΕͨαʔϏεΛ·ͱΊͯ ΤϯυϢʔβʔʹҙຯͷ͋Δ୯ҐͰ αʔϏεΛఏڙ͢Δπʔϧ
খׂ͘͞͞ΕͨαʔϏεʁ
Modular Container Design
ɹେ͖ͳ՝Λখ͞ͳ՝ʹΘ͚͍ͯ͜͏ɻ ΑΓՄ༻ੑ͕ߴ͘εέʔϧ͢ΔΑ͏ʹ ؔ৺Ϧιʔεͯ͠ ɹ֤ίϯςφʹಠཱͨ͠໌֬ͳڥքΛɻ ɹ࠷ऴతͳαʔϏεͦΕΒΛΈ߹Θͤͯʂ
ɹͲͪΒ͕ΑΓ·͍͠ઃܭʁ
$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"
$BTF" CJUOBNJXPSEQSFTT DPOUBJOFS ɾγϯϓϧͰ͍ͦ͢͏ ɾ֤Ϟδϡʔϧ୯ҐͰཧ͍͢͠ ɾOHJOY͚ͩόʔδϣϯΞοϓʗઃఆมߋ ɾXPSEQSFTT͚ͩεέʔϧ ɾNBSJBECΛNZTRMʹஔ͖͑
ɾؔ৺͕͞Ε͍ͯΔ ɾIUUQ ੩తϑΝΠϧΩϟογϡOHJOY ɾCBDLVQSFTUPSFNBSJBEC ɾʢ͜ͷྫඍົ͚ͩͲʣՄ༻ੑΛߴΊΒΕΔ ɾ%#͕ࢮΜͰιʔϦʔϖʔδͩͤΔ $BTF# OHJOY DPOUBJOFS XPSEQSFTT DPOUBJOFS NBSJBEC DPOUBJOFS
దͳϞδϡʔϧʹׂ͞Ε͍ͯΕ αʔϏεશମ͕҆ఆͯ͠εέʔϧ͢Δ
αʔϏεͷ෦తͳΞοϓσʔτͰ͖Δ͠ όάϑΟοΫεͦͷϞδϡʔϧΛ͏ ͋ΒΏΔαʔϏεʹ͙͢ద༻Ͱ͖Δ ʮमਖ਼ͷԣల։ʯى͖ͳ͍
ʢϚΠΫϩαʔϏεಛ༗ͷɺ৽͍͠՝Λ ผ్ղܾ͢Δඞཁ͋Δ͚Ͳʣ
ʢಛʹ։ൃڥͳΒʣ EPDLFSDPNQPTFΛ͑ Ϟδϡʔϧͳߏཧ͍͢͠Αʁ
docker-compose patterns [ جຊܗɾςϯϙϥϦܥ ]
EPDLFSฤʹ͋ΔEPDLFSDPNQPTFZNM ͦΕ͕ͯ͢ͳͷͰׂѪ͠·͢
docker-compose patterns [ Networking ]
Ұ൪ޠΓ͔ͨͬͨͷ͜͜ͳΜͰ͕͢ ർΕͨͷͰ·ͨͷػձʹৡΓ·͢
EPDLFSDPNQPTFQBUUFSO
Appendix
![FNCVUTV͞Μ
PS[ˡࢲʢલဠϑΝϯʣ
Θͨ͠ͷ-5ͷഒ༗ҙٛͳͷͰ ͜Ε͚ͩԱ͑ͯؼ͍ͬͯͩ͘͞
ίϯςφٕज़ͱීٴ͕γεςϜɾΠϯςάϨʔλʹ༩͑ΔӨڹz 1SFTFOUFECZ.BTBIJUP;FNCVUTV 5FDIOPMPHZ&WBOHFMJTU IUUQXXXTMJEFTIBSFOFU[FNCVUTVEPDLFSJNQBDUUPTZTUFNJOUFHSBUJPOT NEW!!