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で社内外の環境を整えた話
Search
Ryo Tomidokoro
May 21, 2016
Programming
1
4.7k
dockerで社内外の環境を整えた話
PHPカンファレンス福岡2016
小規模な受託開発の会社で、開発・ステージング環境用途として
dockerを利用した際の経験談&まとめです。
Ryo Tomidokoro
May 21, 2016
Tweet
Share
More Decks by Ryo Tomidokoro
See All by Ryo Tomidokoro
集中して作業する技術/how_to_work_deeply
hanhan1978
61
40k
PHPでデータベースを作ってみた/create-data-with-php
hanhan1978
10
9.1k
ADRを一年運用してみた/adr_after_a_year
hanhan1978
8
3.4k
B+木入門:PHPで理解する データベースインデックスの仕組み/b-plus-tree-101
hanhan1978
5
4.5k
ADRを一年運用してみた/our_story_about_adr
hanhan1978
5
2k
PHPで学ぶ Session の基本と応用 / web-app-session-101-2024
hanhan1978
12
5.5k
レガシー回避のPHP開発術/avoid_php_legacy
hanhan1978
16
12k
Laravel Collectionの計算量を調べてみた2023/laravel_collection_time_complexity_2023
hanhan1978
1
1.4k
PHP で学ぶ Cache の距離の話 / study_cache_with_php
hanhan1978
7
2.1k
Other Decks in Programming
See All in Programming
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
330
CSC509 Lecture 09
javiergs
PRO
0
140
Realtime API 入門
riofujimon
0
150
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.4k
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
Contemporary Test Cases
maaretp
0
130
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
Jakarta EE meets AI
ivargrimstad
0
120
Remix on Hono on Cloudflare Workers
yusukebe
1
280
Macとオーディオ再生 2024/11/02
yusukeito
0
370
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
100
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Into the Great Unknown - MozCon
thekraken
32
1.5k
Producing Creativity
orderedlist
PRO
341
39k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
BBQ
matthewcrist
85
9.3k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
Facilitating Awesome Meetings
lara
50
6.1k
Transcript
dockerͰࣾ֎͚ͷڥΛ͑ͨ 3ZP5PNJEPLPSP !IBOIBO PHPΧϯϑΝϨϯεԬ
@hanhan1978 Twitter Ryo Tomidokoro Name Web App Engineer Job
"CPVU.F
"HFOEB ͰdockerΛ෮श ׆༻ྫɾߏྫ ॴɾॴ docker࠾༻͢Δ ಋೖཧ༝
ͰEPDLFSΛ෮श Docker Inc ͷιϑτΣΞ ܰྔͳίϯςφԾԽ ϋΠύʔόΠβʔܕͰͳ͍ɻ ίϯςφϗετOSͷִ͞ΕͨڥͰಈ࡞ ֤ίϯςφϗετOSͷࢿݯΛར༻͢Δ
ͰEPDLFSΛ෮श dockerԿ͕خ͍͠ͷʁ ίϯςφΛߏஙɾཧ͢ΔͨΊͷΠϯλϑΣʔεΛఏڙ ߏங༰Dockerfileͱ͍͏ܗͰίʔυԽ dockerͷίϯςφͷϨΠϠʔߏ %PDLFSpMFͷίʔυͷߦߦ͕ϕʔεΠϝʔ δͷ্ʹͱͯ͠ੵΈॏͳ͍ͬͯ͘ɻ ϕʔεΠϝʔδ͔ΒͷϨΠϠʔશମΛؚΊͯɺ ίϯςφͷʮΠϝʔδʯͱݺͿɻ
EPDLFSެࣜΑΓҾ༻
ͰEPDLFSΛ෮श Dockerfileͷத ίϯςφΠϝʔδͷߏஙखॱ େ·͔ʹ͚ΔͱҎԼͷ̏ͭ 1 ϕʔεΠϝʔδࢦఆ Πϝʔδߏங༻ͷίϚϯυ ࿐ग़͢Δportͱ࣮ߦίϚϯυ 2
3
ͰEPDLFSΛ෮श Dockerfileͷ࣮ྫ FROM php:7.0-apache Maintainer hanhan1978 RUN docker-php-ext-install -j$(nproc)
mysql RUN a2enmod rewrite EXPOSE 8080 CMD [“/usr/sbin/httpd”, “-D”, “FOREGROUND”] 1 2 3
ͰEPDLFSΛ෮श ϕʔεΠϝʔδͷऔಘ FROM php:7.0-apache Maintainer hanhan1978 1 phpͷόʔδϣϯ7(Apache)Πϝʔδ ίϯςφͷཧऀࣗͷDocker
ID
ͰEPDLFSΛ෮श ϕʔεΠϝʔδͲ͔͜Βʁ σϑΥϧτެࣜϨϙδτϦ privateϦϙδτϦ༗ྉ EPDLFSIVC EPDLFSSFHJTUSZ OSSͷdocker image ετΞ
ࣗલͰ༻ҙ ઐͷΠϯϑϥ୲͕͍ͳ͍ձࣾͷ߹ ϝϯςೝূ͕໘ͳͷͰΊͨํ͕ແ
ͰEPDLFSΛ෮श Πϝʔδߏங༻ͷίϚϯυ RUN docker-php-ext-install -j$(nproc) mysql RUN a2enmod rewrite
2 • ίϚϯυΛ࣮ߦ͢ΔΑ͏ͳΠϝʔδͰཏྻ • ϩʔΧϧʹ༻ҙͨ͠ϑΝΠϧΛΠϝʔδʹCOPYͱ͔Մ • ৄ͘͠ެࣜυΩϡϝϯτࢀর
FYQPTFͨ͠ϙʔτɺίϯςφؒͰެ։ ͰEPDLFSΛ෮श ࿐ग़͢Δportͱ࣮ߦίϚϯυ EXPOSE 8080 CMD [“/usr/sbin/httpd”, “-D”, “FOREGROUND”]
3 • dockerͷωοτϫʔΫͰ8080൪Λެ։ • CMDͰࢦఆͨ͠ϑΥΞάϥϯυͷίϚϯυΛ࣮ߦ
ͰEPDLFSΛ෮श ίϯςφΛϏϧυ $ docker build -t [Πϝʔδ໊] [Dockerfileͷ͋ΔPATH] docker-hubͷΠϝʔδ໋໊نଇʹै͍·͠ΐ͏
[Ϣʔβ໊]/[Πϝʔδ໊] ྫ) hanhan1978/php7
ͰEPDLFSΛ෮श ίϯςφΛ࣮ߦ $ docker run -d -p 8080:80 [Πϝʔδ໊]
ίϯςφͰexpose͞Εͨ80൪portΛ ϗετOSͷ8080ʹඥ͚ جຊίϨ͚ͩʂ
ͰEPDLFSΛ෮श γϯϓϧͳdockerߏਤ EPDLFSIVC ֤ίϯςφEPDLFSIVC͔ΒϕʔεΠϝʔδΛQVMM %PDLFSpMFͷهड़ʹԊͬͯɺίϯςφΛCVJME
"HFOEB ಋೖཧ༝ ׆༻ྫɾߏྫ ॴɾॴ docker࠾༻͢Δ ͰdockerΛ෮श
ಋೖཧ༝ ձࣾͰ͍ͬͯΔۀ w খʙதنͷडୗ։ൃ w 6*σβΠϯϑϩϯτΤϯυ։ൃ͕ϝΠϯ w αʔϏε։ൃ༗Γ w
4BB4Ͱେମ͏·ͬͯ͘Δ
ಋೖཧ༝ ๊͍͑ͯͨ w ϚʔΫΞοϓ ੩త)5.- ͷ֬ೝڥ͕ແ͔ͬͨɻ w ࢼͯ͠Έ͍ͨ044Λࢼ͢ڥ͕ແ͍ɻ w
#PUͱ͔Λৗறͤ͞Δ-BCతͳڥ͕ແ͍ɻ
ಋೖཧ༝ ݕ౼ͨ͠αʔϏε ࣾʹैྔ՝ۚͷߴֹٻτϥϚ͕͋ΔΒ͘͠ ࠜڧ͍ෆ৴ײ͕ɾɾɾ AWS or GCP Heroku OSSͰHeroku͓ࢼ͠Λఏڙ͍ͯ͠ͳ͍ͷଟ͔ͬͨ
ࣗ༝͕͍ͷͰͱײͨ͡(ޙʑޙչ͕ͨ͠ɾɾɾ) SakuraͷVPS ఆֹͰ͑Δ͠ɺ͖ͳΑ͏ʹ͑ͦ͏ͩɾɾɾ
ಋೖཧ༝ ఆֹ714 ϝϯςָ͕ ߴՄ༻ੑ Ϟμϯ ͱ͍͏Θ͚Ͱ
"HFOEB ׆༻ྫɾߏྫ ಋೖཧ༝ ॴɾॴ docker࠾༻͢Δ ͰdockerΛ෮श
׆༻ྫɾߏྫ Overview DPOUBJOFS DPOUBJOFS DPOUBJOFS DPOUBJOFS ୯ҰͷϗετͷΈར༻ ίϯςφؒϦϯΫportͷࢦఆdocker-compose kubernatisTXBSNඞཁͳ͠ʂ
׆༻ྫɾߏྫ docker-compose ίϯςφ࣮ߦ࣌ͷઃఆZNMͰҰݩཧ mysql: image: mysql volumes: - /host/mysql:/var/lib/mysql
restart: always gyazo: build: docker-files/gyazo environment: - SRC_PATH=/hoge/fuga restart: always
׆༻ྫɾߏྫ 1. ੩తαΠτͷ֬ೝڥ DPOUBJOFS git pushͰCI௨ docker-compose build [container]
ϑϩϯτΤϯυΤϯδχΞɺΫϥΠΞϯτͷαΠτߋ৽ͷڞ༗Λ ҙࣝ͠ͳͯ͘Α͘ͳͬͨɻ ͱʹ͔͘ૣ͘ίʔυΛॻ͍ͯɺ164)
׆༻ྫɾߏྫ 2. OSS͓ࢼ͠ڥ docker-compose up -d opengrok opengrok: image:
itszero/opengrok volumes: - /hoge/fuga:/src ports: - “3001:8080" DPNQPTFZNMʹઃఆΛՃͯ͠UP͢Δ͚ͩ
׆༻ྫɾߏྫ 3. ։ൃ -> εςʔδө ։ൃ DPOUBJOFS DPOUBJOFS DPOUBJOFS
DPOUBJOFS ʹEPDLFSGPSNBD CFUB ग़ͨͷͰɺͦΕͰ0, εςʔδ ։ൃ࣌ͷߏͰͦͷ··UPͰ͖Δʂॴཁ࣌ؒ
"HFOEB ॴɾॴ ಋೖཧ༝ ׆༻ྫɾߏྫ docker࠾༻͢Δ ͰdockerΛ෮श
ॴɾॴ ྑ͔ͬͨ͜ͱ ϗετগͳͷͰϝϯςָ͕ ΞϓϦͷ͓ࢼ͠ར༻ϚδͰָ ґଘؔίϯςφଆͰղܾ͞Ε͍ͯΔ gitlab, redmine => Έͳ͞·Πϯετʔϧ࣌ͷਏ͞ʹ͕֮͑͋Δ͔ͱɾɾɾ
VMΛෳ্ཱ͍ͪ͛ͯͨ࣌ʹൺΔͱஈҧ͍ => ͕֮͑ͯΒΕΔݸ ੬ऑੑରԠ => ίϯςφ࠶Ϗϧυ & ϗεταʔόʹରԠͰOK
ॴɾॴ ྑ͔ͬͨ͜ͱ dockerೲͱ͍͏ϦΫΤετ ސ٬ଆ͕dockerΠϯϑϥΛ͍࣋ͬͯͨ => dockerڥͳΜͰ͕͢ɾɾɾʹ༨༟ͰରԠ ͜ͷઌ૿͑ͯ͘Δͱ༧͞Ε·͢ ʘ(^o^)ʗ
ॴɾॴ ѱ͔ͬͨ͜ͱ ਓࡐϘτϧωοΫ ੩తαΠτߏஙͷίϯςφ࡞ => ٸ͍Ͱ30 ϑϩϯτΤϯυΤϯδχΞͷΈͰ݁Ͱ͖ͳ͍ => ݁ہɺherokuΛ͏͜ͱʹͨ͠
docker-machineͷͭΒΈ VirtualBoxͰಈ࡞͢ΔdockerͳͷͰɺϗετϚγʔϯଆͱͷ௨৴ ϑΝΠϧڞ༗ͳͲ͕໘ ɹ=> docker for mac, windows͕ٹੈओ͔
ॴɾॴ ѱ͔ͬͨ͜ͱ disk༰ྔ VPSͱ͔݁ߏdisk༰ྔগͳ͍ܖͩͱਏ͘ͳΔ ΠϝʔδϨΠϠʔ͕δϫδϫͱѹഭ => 20ʙ30ఔͷίϯςφΠϝʔδͰ50G͘Β͍ݟͨ΄͏͕ྑ ͍͔ɻ
ॴɾॴ ݸਓతͳײ w %PDLFSpMFͬͯɺ͋Μ·Γے͕ΑΖ͘͠ࢥ͑ͳ͍ɻ΄΅TIFMM w EPDLFSGPSNBD XJOEPXTظͰ͖Δʂʂ w 044ͷ͓ࢼ͠༻్ͱͯ͠ɺ࠷ڧͷڥɹେͷͷEPDLFS
IVCʹ͋Δ w ੈͷதʹ͍͍͚ͭͯͯΔײຯͰ͕͢େࣄ
"HFOEB docker࠾༻͢Δ ಋೖཧ༝ ׆༻ྫɾߏྫ ॴɾॴ ͰdockerΛ෮श
docker࠾༻͢Δʁ ೦಄ʹ͓͍͓ͯ͘͜ͱ w EPDLFSͷݪཧΛཧղ͠ɺཧՄೳͳਓࡐΛਓଗ͍͑ͨɻ w શ෦ΛEPDLFSͰΕΔͱ͍͏ࢥߟఀࢭ/(Ϛωʔδυɾ αʔϏεͰແྉͱ͔͋Δ͠ɺόοΫΤϯυΤϯδχΞෆཁ ͷιϦϡʔγϣϯΛୈҰʹߟ͑Δͷେࣄ w
ίϯςφࣗମΛඞཁͱ͢ΔαʔϏε։ൃͰ͋ΕɺEPDLFSΛ ͏ͷݮʹͳͬͯྑͦ͞͏ɻ
dockerͬͯΈΔʁ ৭ʑݒ೦͋͛·͕ͨ͠ɾɾɾ ͳΜ͔ͩΜͩݴͬͯɺdockerָ͍ͬ͢͠ ͪΐͬͱ͘Β͍ᷖᮣͳײ͕͡ͳ͍ͱɺ৽نಋೖͳΜͯͰ͖ͳ͍YO
͓·͚ dockerͰPHPڥ EPDLFSIVCʹ1)1ͷެࣜΠϝʔδ༗Γ w ʙͷOUTͱ[UT w QIQGQN BQBDIF DMJ
w BMQJOFͱॻ͔Ε͍ͯΔͷܰྔΠϝʔδ
͓·͚ apacheͷ߹ Containers BQBDIF src w ެࣜΠϝʔδQSFGPSLNPEQIQ w EPDVNFOU3PPUʹTSDΛಥͬࠐΉ͚ͩ
͓·͚ php-fpmͷ߹ Containers /HJOY src w /HJOYͷ'BTU$(*ͷαʔόΛલஈʹઃஔ w QIQGQNͷ෦IIWNͱ͔ʹஔՄೳ
QIQGQN
"OZ2VFTUJPO ಋೖཧ༝ ׆༻ྫɾߏྫ ॴɾॴ ͰdockerΛ෮श docker࠾༻͢Δ