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で作るPHP開発環境(入門編)
Search
Takashi Nojima
September 12, 2018
Technology
3
960
Dockerで作るPHP開発環境(入門編)
2018.09.12 博多TECH塾
デモ・サンプルコード
https://github.com/nojimage/hakata-tech-php-docker/tree/master/vol0
Takashi Nojima
September 12, 2018
Tweet
Share
More Decks by Takashi Nojima
See All by Takashi Nojima
Stripe決済対応 バリカートの紹介と本カートシステムでの Stripe連携の仕組み
nojimage
0
140
CakePHP3で時間を 扱いたかったお話 / Fukuoka.php 201904
nojimage
0
330
CakePHP3 Modelless Form
nojimage
3
2.7k
Codeceptionでテストをしよう
nojimage
0
1.6k
Other Decks in Technology
See All in Technology
APIとはなにか
mikanichinose
0
110
組織に自動テストを書く文化を根付かせる戦略(2024冬版) / Building Automated Test Culture 2024 Winter Edition
twada
PRO
18
5.5k
怖くない!ゼロから始めるPHPソースコードコンパイル入門
colopl
0
160
Oracle Cloud Infrastructure:2024年12月度サービス・アップデート
oracle4engineer
PRO
1
270
OCI技術資料 : ファイル・ストレージ 概要
ocise
3
11k
終了の危機にあった15年続くWebサービスを全力で存続させる - phpcon2024
yositosi
27
23k
Oracle Cloudの生成AIサービスって実際どこまで使えるの? エンジニア目線で試してみた
minorun365
PRO
4
300
KnowledgeBaseDocuments APIでベクトルインデックス管理を自動化する
iidaxs
1
280
エンジニアカフェ忘年会2024「今年やらかしてしまったこと!」
keropiyo
0
100
C++26 エラー性動作
faithandbrave
2
820
1等無人航空機操縦士一発試験 合格までの道のり ドローンミートアップ@大阪 2024/12/18
excdinc
0
180
Microsoft Azure全冠になってみた ~アレを使い倒した者が試験を制す!?~/Obtained all Microsoft Azure certifications Those who use "that" to the full will win the exam! ?
yuj1osm
2
120
Featured
See All Featured
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.5k
Documentation Writing (for coders)
carmenintech
67
4.5k
Statistics for Hackers
jakevdp
796
220k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Done Done
chrislema
182
16k
Scaling GitHub
holman
459
140k
Embracing the Ebb and Flow
colly
84
4.5k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
66k
Into the Great Unknown - MozCon
thekraken
33
1.5k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
Transcript
DockerͰ࡞ΔPHP։ൃڥ ʢೖฤʣ തଟTECHक़ Vol.55 2018.09
About Me ໊લɿౡོʢͷ͡·͔ͨ͠ʣ ॴଐɿΠϥεςΟοΫίϯαϧλϯπגࣜձࣾ IUUQTFMBTUJDDPOTVMUBOUTDPNʲٻਓதʂʳ ‣ CMPHIUUQTQIQUJQTDPN ‣ (JUIVC5XJUUFSOPKJNBHF
͢͜ͱ ‣ 1)1ΞϓϦέʔγϣϯͷ։ൃڥ͋Ε͜Ε ‣ %PDLFSͱ ‣ %PDLFSڥͷߏஙํ๏ ‣ )FMMP1)1PO%PDLFS ‣
%PDLFS$PNQPTFͰ։ൃڥΛͭ͘Δ
PHP։ൃڥ͋Ε͜Ε
डୗ։ൃͰͷPHP։ൃڥ ‣ डୗ։ൃʹ͓͍ͯҊ݅͝ͱʹ༻Ͱ͖Δ1)1όʔδϣ ϯ͕ҟͳΔ ‣ ։ൃϚγϯʹҊ݅͝ͱʹຊ൪ڥʹԠͨ͡όʔδϣ ϯͷ։ൃڥΛ༻ҙ͢Δ
डୗ։ൃͰͷPHP։ൃڥ ‣ ։ൃڥͷόʔδϣϯ͕ຊ൪ڥͷόʔδϣϯ͕ҟͳ Δͱ ݹ͍όʔδϣϯͰར༻Ͱ͖ͳ͍จ๏ؔΛ༻ͯ͠͠·͏ όʔδϣϯʹΑͬͯڍಈͷมΘͬͨؔΛ༻ͯ͠͠·͏ ʮ։ൃڥͰಈ͍͍ͯͨͷʹຊ൪ڥͰಈ͔ͳ͍ʯ
डୗ։ൃͰͷPHP։ൃڥ ʮ։ൃڥͰಈ͍͍ͯͨͷʹຊ൪ڥͰಈ͔ͳ͍ʯ Λආ͚ΔͨΊʹ ຊ൪ڥʹ͍ۙڥΛ։ൃڥͱͯ͠ར༻͢Δ Ҋ݅͝ͱʹ։ൃڥΛΓ͚ͯ࡞͢Δ ෳਓͰ։ൃ͢Δ߹ಉ͡։ൃڥΛఏڙ͢Δ
ෳόʔδϣϯͷڥΛ ߏங͢ΔͨΊͷπʔϧ
phpenv + php-build ‣ ϩʔΧϧϚγϯ্ͷQIQόʔδϣϯͷସ͑ ‣ ϩʔΧϧͰDPNQPTFSQIQVOJUΛ࣮ߦ͢Δ࣌ʹ༻ σΟϨΫτϦ͝ͱʹόʔδϣϯΛઃఆɾସ͑Ͱ͖Δ ‣ QIQCVJMEͰҙͷόʔδϣϯͷ1)1ΛΠϯετʔϧͰ͖Δ
QIQCVJMEιʔείʔυ͔ΒϏϧυ͢ΔͷͰ͕͔͔࣌ؒΔ ґଘϥΠϒϥϦͷΞοϓσʔτͰϦϯΫ͕Εͨ߹ͳͲ ࠶Ϗϧυʜ
Vagrant / VirtualBox ‣ Ҋ݅ຖʹԾϚγϯΛߏஙͯ͠։ൃڥͱ͢Δ ຊ൪ڥͱ΄΅ಉҰͷڥΛߏஙՄೳ ‣ σΟϨΫτϦߏɺϛυϧΣΞΛؚΊͯಉҰԽͰ͖Δ ԾϚγϯͳͷͰىಈʹগʑ͕͔͔࣌ؒΔ ԾϚγϯ04Λؙ͝ͱؚΉͷͰσΟεΫ༰ྔΛଟ͘ফඅ
σΟεΫΠϝʔδ͕େ͖͍ͷͰ։ൃڥͷڞ༗͕͍ͨΜ
Docker ‣ Ҋ݅ຖʹEPDLFSNBDIJOFͰԾϚγϯΛߏங ‣ ԾϚγϯͷதͰ%PDLFSίϯςφΛىಈͯ͠։ൃڥΛߏங 7BHSBOUʹൺ04Λؚ·ͳ͍σΟεΫ༰ྔΛফඅ͠ͳ͍ ։ൃڥͷڞ༗%PDLFSΠϝʔδΛ͢Ε͍͍ ։ൃʹ༻ͨ͠ίϯςφΛຊ൪ڥͰ༻͢Δ͜ͱՄೳ
ͱ
‣ ίϯςφܕͷԾڥΛ࡞ɺɺ࣮ߦ͢ΔͨΊͷ ϓϥοτϑΥʔϜ ‣ -JOVYΧʔωϧ͕ݩʑ͍࣋ͬͯΔػೳΛͬͯɺ࣮ߦ ڥΛଞͷϓϩηε͔Βִ͠ɺͦͷதͰΞϓϦέʔγϣ ϯΛಈ࡞ͤ͞Δ ‣ ैདྷͷԾԽٕज़ʢ)ZQFS7 7JSUVBM#PYʣͱൺϦ
ιʔεͷফඅΦʔόʔϔου͕গͳ͍
ϋʔυΣΞ ϗετ04 ԾԽιϑτ ήετ04 ϛυϧΣΞ ΞϓϦ ήετ04 ϛυϧΣΞ ΞϓϦ ϋʔυΣΞ
ϗετ04 %PDLFS&OHJOF ԾϚγϯ ίϯςφ ϛυϧΣΞ ΞϓϦ ϛυϧΣΞ ΞϓϦ ԾϚγϯ ίϯςφ ԾϚγϯͱDockerͷҧ͍
༻ޠ ‣ %PDLFSίϯςφ %PDLFS&OHJOF্Ͱىಈ͞ΕΔ࣮ߦڥ %PDLFSΠϝʔδ͔Βίϐʔͯ͠ੜ͢Δ ‣ %PDLFSΠϝʔδ ίϯςφͷݩͱͳΔϑΝΠϧγεςϜɻಡΈࠐΈઐ༻ ‣ %PDLFSpMF
ΠϝʔδΛ࡞͢ΔͨΊͷखॱΛॻ͍ͨϑΝΠϧ
Dockerfile→Πϝʔδ→ίϯςφ %PDLFSpMF %PDLFS Πϝʔδ %PDLFS ίϯςφ EPDLFSCVJME EPDLFSSVO
DockerΠϝʔδΛऔಘ͢Δ %PDLFS Πϝʔδ %PDLFS ίϯςφ EPDLFSQVMM EPDLFSSVO ΠϝʔδϨδετϦ
Dockerڥͷߏங
Windows/MacͰͷDockerڥ ‣ %PDLFS%FTLUPQ %PDLFSGPS8JOEPXT.BD IUUQTXXXEPDLFSDPNQSPEVDUTEPDLFSEFTLUPQ ‣%PDLFS.BDIJOF IUUQTEPDTEPDLFSDPNNBDIJOF
Docker for Windows/Mac ͱ Docker Machine ͷҧ͍ ϋʔυΣΞ 8JOEPXTNBD04 )ZQFS7YIZWF
ϋʔυΣΞ ϗετ04 %PDLFS&OHJOF %PDLFSGPS8JOEPXT.BD %PDLFS.BDIJOF ϛυϧΣΞ ΞϓϦ ϛυϧΣΞ ΞϓϦ ԾԽιϑτ ήετ04 %PDLFS&OHJOF ϛυϧΣΞ ΞϓϦ ϛυϧΣΞ ΞϓϦ
Docker Machineͷεεϝ Ҋ݅͝ͱʹԾϚγϯΛ࡞͢ΕɺෳҊ݅ͷίϯςφΛಉ࣌ʹ ্ཱͪ͛ͯϙʔτͷ͔ͿΓ͕ͳ͍ ԾϚγϯຖʹ*1͕ৼΒΕΔͷͰIPTUTͰ໊લղܾ͕Մೳ ԾϚγϯͷσΟεΫ༰ྔΛফඅͯ͠͠·͏ ϗετϚγϯʹϙʔτϚοϐϯά͢ΔΘ͚Ͱͳ͍ͷͰɺ ଞͷϚγϯ͔ΒΞΫηεͰ͖ͳ͍ ˠϗετϚγϯʹ8FCαʔόΛཱ͔ͯͯͦ͜ΒϓϩΩγͰԾϚγϯʹඈ͢ํ๏ͰΞΫηεՄೳ
DockerͷΠϯετʔϧ
Docker DesktopΛΠϯετʔϧ ‣ IUUQTXXXEPDLFSDPNQSPEVDUTEPDLFSEFTLUPQ
Docker DesktopΛΠϯετʔϧ
Docker DesktopΛΠϯετʔϧ
Docker DesktopΛΠϯετʔϧ ্2ͭͷνΣοΫϘοΫεඞਢ ར༻نͱϓϥΠόγʔϙϦγʔͷಉҙ ొ֬ೝͷϝʔϧ͕ඈΜͰ͘ΔͷͰ ϝʔϧͷϦϯΫΛΫϦοΫͯ͠ొྃ
Docker DesktopΛΠϯετʔϧ
Docker DesktopΛΠϯετʔϧ
Docker DesktopΛΠϯετʔϧ ‣ Πϯετʔϧޙɺίϯιʔϧ͔ΒEPDLFSWFSTJPO ͱଧͬͯىಈΛ֬ೝ $ docker version Client: Version:
18.06.1-ce API version: 1.38 Go version: go1.10.3 Git commit: e68fc7a Built: Tue Aug 21 17:21:31 2018 OS/Arch: darwin/amd64 Experimental: false Server: Engine: Version: 18.06.1-ce API version: 1.38 (minimum version 1.12) Go version: go1.10.3 Git commit: e68fc7a Built: Tue Aug 21 17:29:02 2018 OS/Arch: linux/amd64 Experimental: true ClientͱServer྆ํͷόʔδϣϯ͕ දࣔ͞Ε͍ͯΕOK
Hello PHP on Docker
PHPެࣜΠϝʔδ ‣ %PDLFS)VCIUUQTIVCEPDLFSDPN ‣ %PDLFSΠϝʔδͷϨϙδτϦ ‣ 1)1ެࣜͷΠϝʔδ IUUQTIVCEPDLFSDPN@QIQ ‣ d
CFUB ·Ͱ͋Δ
None
PHPެࣜΠϝʔδ ‣ 1)1ͷΠϝʔδʹ৭ʑͳछྨ͕͋Δ ‣ DMJ ‣ GQN ‣ BQBDIF ‣
DMJBMQJOF ‣ GQNBMQJOF ‣ DMJBMQJOF ࠷ॳͷࣈ1)1όʔδϣϯ DMJ$-* ίϚϯυϥΠϯ ൛ GQN1)1'1.൛ BQBDIF"QBDIFIUUQEಉࠝ൛ [UT;54ʢ;FOE5ISFBE4BGFUZʣରԠ൛ ௨ৗ%FCJBOϕʔε BMQJOF͕ͭ͘ͱΑΓܰྔͳ"MQJOF-JOVYϕʔε
σϞ
DockerΠϝʔδΛpull͢Δ ‣ ࠓճBQBDIFΛ༻ͯ͠ΈΔ ‣docker pull php:7.2-apache ‣ docker imagesͰखݩͷΠϝʔδͷϦετΛ֬ೝ
hello.phpΛ༻ҙ͢Δ <?php $version = phpversion(); $sapi = PHP_SAPI; ?> <h1>Hello
PHP <?= $version ?> on <?= $sapi ?></h1>
PHPίϯςφΛىಈ͢Δ docker run \ --rm \ -p 8000:80 \ -v
"$PWD":/var/www/html \ php:7.2-apache ˡίϯςφΛىಈ ˡίϯςφΛऴྃͨ͠Βআ͢Δ ˡίϯςφͷϙʔτΛϗετͷʹׂΓͯ ˡݱࡏͷσΟϨΫτϦΛWBSXXXIUNMʹϚϯτ ˡQIQBQBDIFͷΠϝʔδ͔Β࣮ߦ IUUQMPDBMIPTUͰΞΫηεͰ͖Δ
CLIͰPHPΛىಈ͢Δ docker run \ --rm \ -v "$PWD":/var/www/html \ php:7.2-apache
\ php hello.php ˡίϯςφΛىಈ ˡίϯςφΛऴྃͨ͠Βআ͢Δ ˡݱࡏͷσΟϨΫτϦΛWBSXXXIUNMʹϚϯτ ˡQIQBQBDIFͷΠϝʔδ͔Β࣮ߦ ˡQIQίϚϯυͰIFMMPQIQΛ࣮ߦ
DockerͰ͓͖͍֮͑ͯͨίϚϯυ ‣ EPDLFSQVMM ‣ EPDLFSSVO ‣ EPDLFSQTEPDLFSQTB ‣ EPDLFSMPHT ‣
EPDLFSJNBHFT
ΧελϜPHPΠϝʔδΛ࡞
ެࣜΠϝʔδͰΓͳ͍ ‣ ެࣜΠϝʔδʹσϑΥϧτͰೖ͍ͬͯΔ1)1֦ுͰ ࣮ࡍͷ։ൃͰ͖ͳ͍ ‣ QEP@NZTRM(% 9EFCVHͳͲΑ͘͏֦ுೖͬ ͍ͯͳ͍ ඞཁͳ֦ுΛΠϯετʔϧͨ͠ %PDLFSΠϝʔδΛ࡞Δ
DockerfileͰ͑Δαϙʔτπʔϧ ‣ 1)1ίΞʹؚ·ΕΔ֦ுΛΠϯετʔϧ͢Δ ‣ EPDLFSQIQFYUJOTUBMM ‣ EPDLFSQIQFYUDPOpHVSF ‣ QFDM֦ுΛΠϯετʔϧ͢Δ ‣
EPDLFSQIQFYUFOBCMF
GD֦ுΛΠϯετʔϧ FROM php:7.2-apache RUN apt-get update \ && apt-get install
-y \ libfreetype6-dev \ libjpeg62-turbo-dev \ libpng-dev \ && docker-php-ext-configure gd \ --with-freetype-dir=/usr/include/ \ --with-jpeg-dir=/usr/include/ \ && docker-php-ext-install gd ˡQIQBQBDIFΛϕʔεʹ͢Δ ˡBQUύοέʔδΞοϓσʔτ ˡ(%ʹඞཁͳύοέʔδΛΠϯετʔϧ ˡ(%֦ுͷϏϧυΦϓγϣϯΛࢦఆ ˡ(%֦ுΛΠϯετʔϧ
Docker ComposeͰ ։ൃڥΛߏங͢Δ
Docker Composeͱ ‣ ෳͷίϯςφ͔ΒΔαʔϏεͷߏɾؔ࿈Λ ϑΝΠϧͰఆٛ͠ཧΛ༰қʹ͢Δπʔϧ ‣ ֤αʔϏείϯςφͷఆٛͳͲهड़ͨ͠ EPDLFSDPNQPTFZNMϑΝΠϧΛ࡞͢Δ ‣ EPDLFSDPNQPTFίϚϯυΛͬͯαʔϏεཧ
EPDLFSίϚϯυͷΈͰෳίϯςφΛ ಈ͔͢ͷਏ͍ͷͰඞਢʂ
WordPressΛDockerͰಈ͔͢ ‣ 1)1"QBDIFͱ.Z42-ͷΈ߹Θͤ ‣ 1)1ΧελϜΠϝʔδɺ.Z42-ެࣜΠϝʔδΛ ༻͢Δ ‣ ࠓճ%PDLFSGPS.BD্Ͱಈ͔͢ "QBDIF 1)1
.Z42- 8PSE1SFTT 8000:80 13306:3306
WordPressΛDockerͰಈ͔͢ ‣ 1)1ΧελϜΠϝʔδͷϙΠϯτ ‣ 8PSE1SFTT.Z42-֦ுPS.Z42-J֦ுΛͬͯ .Z42-ͱଓ͢Δ ‣ ը૾αϜωΠϧͷ࡞ʹ(%·ͨJNBHJDL͕ඞཁ ͜ΕΒͷ֦ு1)1ެࣜΠϝʔδʹ ؚ·Εͳ͍ͷͰཁΠϯετʔϧ
σϞ
·ͱΊ ։ൃڥͳΔ͘ຊ൪ڥͱಉ͡ʹ͠Α͏ ‣ νʔϜͰ։ൃ͢ΔͳΒ։ൃڥΛڞ༗Ͱ͖ΔΑ͏ʹ %PDLFS։ൃڥΛ࡞Δɾڞ༗͢Δͷʹศར ‣ͦͷ··ຊ൪ڥͰར༻͢Δ͜ͱՄೳ %PDLFS$PNQPTFΛͬͯߏΛఆٛ͠Α͏
DockerͷυΩϡϝϯτ ‣%PDLFSެࣜ IUUQTEPDTEPDLFSDPN ‣༗ࢤͷํʹΑΔຊޠ༁ IUUQEPDTEPDLFSKQ ˞WϕʔεʢલʣͷͷͳͷͰҙ
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ Ξϯέʔτͷ͝ճΑΖ͓͘͠ئ͍͠·͢