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
340
CakePHP3 Modelless Form
nojimage
3
2.7k
Codeceptionでテストをしよう
nojimage
0
1.6k
Other Decks in Technology
See All in Technology
[SRE kaigi 2025] ガバメントクラウドに向けた開発と変化するSRE組織のあり方 / Development for Government Cloud and the Evolving Role of SRE Teams
kazeburo
3
1.4k
なぜfreeeはハブ・アンド・スポーク型の データメッシュアーキテクチャにチャレンジするのか?
shinichiro_joya
3
900
タイミーのデータ活用を支えるdbt Cloud導入とこれから
ttccddtoki
2
460
消し忘れリソースゼロへ!私のResource Explorer活用法
cuorain
0
110
Windows Server 2025 へのアップグレードではまった話
tamaiyutaro
2
230
MicrosoftのOSSだけでAIによるブラウザテストを構成する
ymd65536
1
220
HCP Terraformで実現するPlatform Engineering/nikkei-tech-talk-29
nikkei_engineer_recruiting
0
200
2025-01-24-SRETT11-OpenTofuについてそろそろ調べてみるか
masasuzu
0
130
クロスアカウントな RDS Snapshot Export による カジュアルなデータ集約の仕組み / 202501-finatext-technight-lt
wa6sn
1
120
TSのコードをRustで書き直した話
askua
4
980
20250122_個人向けCopilotどうなん
ponponmikankan
0
190
オーティファイ会社紹介資料 / Autify Company Deck
autifyhq
10
120k
Featured
See All Featured
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Building Applications with DynamoDB
mza
93
6.2k
Making Projects Easy
brettharned
116
6k
Bash Introduction
62gerente
610
210k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Unsuck your backbone
ammeep
669
57k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
Designing for humans not robots
tammielis
250
25k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
160
15k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Done Done
chrislema
182
16k
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ϕʔεʢલʣͷͷͳͷͰҙ
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ Ξϯέʔτͷ͝ճΑΖ͓͘͠ئ͍͠·͢