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
950
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
320
CakePHP3 Modelless Form
nojimage
3
2.6k
Codeceptionでテストをしよう
nojimage
0
1.5k
Other Decks in Technology
See All in Technology
【Pycon mini 東海 2024】Google Colaboratoryで試すVLM
kazuhitotakahashi
2
490
Shopifyアプリ開発における Shopifyの機能活用
sonatard
4
250
Lexical Analysis
shigashiyama
1
150
100 名超が参加した日経グループ横断の競技型 AWS 学習イベント「Nikkei Group AWS GameDay」の紹介/mediajaws202411
nikkei_engineer_recruiting
1
170
Lambda10周年!Lambdaは何をもたらしたか
smt7174
2
110
Evangelismo técnico: ¿qué, cómo y por qué?
trishagee
0
360
Exadata Database Service on Dedicated Infrastructure(ExaDB-D) UI スクリーン・キャプチャ集
oracle4engineer
PRO
2
3.2k
ドメイン名の終活について - JPAAWG 7th -
mikit
33
20k
【令和最新版】AWS Direct Connectと愉快なGWたちのおさらい
minorun365
PRO
5
750
CysharpのOSS群から見るModern C#の現在地
neuecc
2
3.1k
AWS Lambdaと歩んだ“サーバーレス”と今後 #lambda_10years
yoshidashingo
1
170
隣接領域をBeyondするFinatextのエンジニア組織設計 / beyond-engineering-areas
stajima
1
270
Featured
See All Featured
The Cult of Friendly URLs
andyhume
78
6k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Being A Developer After 40
akosma
86
590k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Gamification - CAS2011
davidbonilla
80
5k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
Designing Experiences People Love
moore
138
23k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
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ϕʔεʢલʣͷͷͳͷͰҙ
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ Ξϯέʔτͷ͝ճΑΖ͓͘͠ئ͍͠·͢