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
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
事業者間調整の行間を読む 調整の具体事例
sugiim
0
1.5k
【若手エンジニア応援LT会】AWSで繋がり、共に成長! ~コミュニティ活動と新人教育への挑戦~
kazushi_ohata
0
180
物価高なラスベガスでの過ごし方
zakky
0
380
10分でわかるfreeeのQA
freee
1
3.4k
ガチ勢によるPipeCD運用大全〜滑らかなCI/CDを添えて〜 / ai-pipecd-encyclopedia
cyberagentdevelopers
PRO
3
210
「最高のチューニング」をしないために / hack@delta 24.10
fujiwara3
21
3.5k
Datachain会社紹介資料(2024年11月) / Company Deck
datachain
3
16k
来年もre:Invent2024 に行きたいあなたへ - “集中”と“つながり”で楽しむ -
ny7760
0
470
30万人が利用するチャットをFirebase Realtime DatabaseからActionCableへ移行する方法
ryosk7
5
350
独自ツール開発でスタジオ撮影をDX!「VLS(Virtual LED Studio)」 / dx-studio-vls
cyberagentdevelopers
PRO
1
180
visionOSでの空間表現実装とImmersive Video表示について / ai-immersive-visionos
cyberagentdevelopers
PRO
1
110
生成AIと知識グラフの相互利用に基づく文書解析
koujikozaki
1
140
Featured
See All Featured
Side Projects
sachag
452
42k
Visualization
eitanlees
144
15k
StorybookのUI Testing Handbookを読んだ
zakiyama
26
5.2k
[RailsConf 2023] Rails as a piece of cake
palkan
51
4.9k
Why Our Code Smells
bkeepers
PRO
334
57k
Speed Design
sergeychernyshev
24
570
The Cult of Friendly URLs
andyhume
78
6k
Automating Front-end Workflow
addyosmani
1365
200k
Measuring & Analyzing Core Web Vitals
bluesmoon
1
40
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
7.9k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
46
2.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!!