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.2k
ハイブリッド並列 on Kubernetes/hybrid-parallel-program-on-kubernetes
pottava
1
400
AWS Fargate + Code 兄弟で始める継続的デリバリー / Continuous Delivery with AWS Fargate and Code brothers
pottava
12
3k
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
450
Other Decks in Technology
See All in Technology
KubeVirt Networking ONIC 2024
orimanabu
4
640
DenoでもViteしたい!インポートパスのエイリアスを指定してラクラクアプリ開発
bengo4com
2
2k
Road to Single Activity Uncovered
yurihondo
0
100
ドキュメントとの付き合い方を考える
leveragestech
1
150
AWS Lambdaで実現するスケーラブルで低コストなWebサービス構築/YAPC::Hakodate2024
fujiwara3
7
3.7k
From naive to advanced RAG: the complete guide
glaforge
0
150
Grafana エコシステムの活用事例 on ABEMA
tetsuya28
4
320
CData Virtuality を活かせるキーシナリオと製品デモ
cdataj
0
230
TypeScript x Raycast x AIで変える開発者体験
nagauta
1
280
Oracle Database 23ai 新機能#4 Real Application Clusters
oracle4engineer
PRO
0
160
品質マネジメントで抑えておきたい2つのリスクを見分けて未来に備えよう #yapcjapan
makky_tyuyan
0
110
Develop to Survive - YAPC::Hakodate 2024 Keynote
moznion
8
2.9k
Featured
See All Featured
Designing for Performance
lara
604
68k
Code Reviewing Like a Champion
maltzj
519
39k
Pencils Down: Stop Designing & Start Developing
hursman
119
11k
The Art of Programming - Codeland 2020
erikaheidi
51
13k
Git: the NoSQL Database
bkeepers
PRO
425
64k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Done Done
chrislema
181
16k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
Statistics for Hackers
jakevdp
796
220k
No one is an island. Learnings from fostering a developers community.
thoeni
19
2.9k
RailsConf 2023
tenderlove
28
850
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
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!!