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
AIチャットボット開発への生成AI活用
ryomrt
0
170
CysharpのOSS群から見るModern C#の現在地
neuecc
2
3.2k
Lambdaと地方とコミュニティ
miu_crescent
2
370
誰も全体を知らない ~ ロールの垣根を超えて引き上げる開発生産性 / Boosting Development Productivity Across Roles
kakehashi
1
220
SREが投資するAIOps ~ペアーズにおけるLLM for Developerへの取り組み~
takumiogawa
1
190
信頼性に挑む中で拡張できる・得られる1人のスキルセットとは?
ken5scal
2
530
Adopting Jetpack Compose in Your Existing Project - GDG DevFest Bangkok 2024
akexorcist
0
110
これまでの計測・開発・デプロイ方法全部見せます! / Findy ISUCON 2024-11-14
tohutohu
3
370
テストコード品質を高めるためにMutation Testingライブラリ・Strykerを実戦導入してみた話
ysknsid25
7
2.6k
Shopifyアプリ開発における Shopifyの機能活用
sonatard
4
250
ドメインの本質を掴む / Get the essence of the domain
sinsoku
2
150
Platform Engineering for Software Developers and Architects
syntasso
1
520
Featured
See All Featured
Mobile First: as difficult as doing things right
swwweet
222
8.9k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
A better future with KSS
kneath
238
17k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
BBQ
matthewcrist
85
9.3k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
89
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Designing the Hi-DPI Web
ddemaree
280
34k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
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!!