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.3k
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
[CV勉強会@関東 ECCV2024 読み会] オンラインマッピング x トラッキング MapTracker: Tracking with Strided Memory Fusion for Consistent Vector HD Mapping (Chen+, ECCV24)
abemii
0
230
Amplify Gen2 Deep Dive / バックエンドの型をいかにしてフロントエンドへ伝えるか #TSKaigi #TSKaigiKansai #AWSAmplifyJP
tacck
PRO
0
390
OCI 運用監視サービス 概要
oracle4engineer
PRO
0
4.8k
リンクアンドモチベーション ソフトウェアエンジニア向け紹介資料 / Introduction to Link and Motivation for Software Engineers
lmi
4
300k
Making your applications cross-environment - OSCG 2024 NA
salaboy
0
190
OCI Security サービス 概要
oracle4engineer
PRO
0
6.5k
【Pycon mini 東海 2024】Google Colaboratoryで試すVLM
kazuhitotakahashi
2
540
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
100
Exadata Database Service on Dedicated Infrastructure(ExaDB-D) UI スクリーン・キャプチャ集
oracle4engineer
PRO
2
3.2k
ノーコードデータ分析ツールで体験する時系列データ分析超入門
negi111111
0
420
iOSチームとAndroidチームでブランチ運用が違ったので整理してます
sansantech
PRO
0
150
Application Development WG Intro at AppDeveloperCon
salaboy
0
190
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
900
Typedesign – Prime Four
hannesfritz
40
2.4k
Speed Design
sergeychernyshev
25
620
Done Done
chrislema
181
16k
The Language of Interfaces
destraynor
154
24k
Adopting Sorbet at Scale
ufuk
73
9.1k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
4 Signs Your Business is Dying
shpigford
180
21k
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!!