Upgrade to Pro — share decks privately, control downloads, hide ads and more …

今こそ深堀りする、PHPのDockerイメージ / understand_php_docker

今こそ深堀りする、PHPのDockerイメージ / understand_php_docker

PHP Conference Japan 2021の発表資料です。
https://phpcon.php.gr.jp/2021/

トーク中で使用したCakePHPの環境構築
https://github.com/rukiadia/php-sample-docker

スライド中のURL一覧
・PHP公式イメージのタグ一覧
https://github.com/docker-library/docs/blob/master/php/README.md#supported-tags-and-respective-dockerfile-links
・「PHPのレジェンドシステムをEC2からKubernetesに移行する話 その5 〜PHPアプリケーションをコンテナ化しよう〜」
※alpineを見送った事例として紹介させていただいたURL
https://creators-note.chatwork.com/entry/2021/01/13/144022
・「CakePHPのインストール」
https://book.cakephp.org/4/ja/installation.html
・intl拡張モジュールのインストール要件
https://www.php.net/manual/ja/intl.requirements.php
・拡張モジュールの一覧/分類
https://www.php.net/manual/ja/extensions.php
・Dockerfileのコードリーディングに使用したイメージ
https://github.com/docker-library/php/blob/8d98db4cebcdf5ff776e2d0b9bf4a5b482f4e657/8.0/bullseye/cli/Dockerfile

438799c739f93d00abc30fa2da33c543?s=128

TwitterID:@rukiadia

October 02, 2021
Tweet

Transcript

  1. ࠓͦ͜ਂງΓ͢Δɺ 1)1ͷ%PDLFSΠϝʔδ ʰ1)1$POGFSFODF+BQBOʱ !SVLJBEJB 4IP:BNBEB

  2. ܰࣗ͘ݾ঺հ • ࢁాɹ঵ʢ΍·ͩɹ͠ΐ͏ʣ • Twitter : @rukiadia • PHP Conferenceʹొஃͤͯ͞΋Β͏ͷ͸ೋճ໨

    • ίωώτגࣜձࣾͰόοΫΤϯυΤϯδχΞΛ͍ͯ͠·͢ɻ • ʮCakePHPʯʮTypeScript x React ʯΛॻ͘ࣄ͕ଟ͍Ͱ͢ɻ
  3. ࠓ೔ͷϝΠϯςʔϚ w ެࣜͷΠϝʔδΛௐ΂ͯجຊΛ཈͑ɺΠϝʔδͷҧ͍Λ஌Δɻ w $BLF1)1ͷಈ࡞؀ڥΛ࡞ΔྲྀΕΛ௥͍ͭͭɺύοέʔδͷґଘؔ܎ Λ஌Δɻ w ϓϨʔϯͳ04ͷΠϝʔδΛ࢖͍͍ͨ৔߹͸Ͳ͏͢Δ͔Λ஌Δɻ

  4. ࠓ೔ͷϝΠϯςʔϚͰ͸ͳ͍͜ͱ w %PDLFSͷجૅʹؔ͢Δ࿩ w ʮEPDLFSDPNQPTFͱ͸ʁʯΈ͍ͨͳ࿩΋͠·ͤΜɻ w %PDLFSΠϝʔδͷαΠζΛ࡟ΔͨΊͷϕετϓϥΫςΟε τʔΫςʔϚ͸͋͘·Ͱ1)1ʂʂ ʢ1)1ΧϯϑΝϨϯεͰ͔͢ΒͶʣ

  5. ͸͡Ίʹ ͜ͷτʔΫΛ࿩͍ͨ͠ͱࢥͬͨ Ϟνϕʔγϣϯ

  6. τʔΫͷϞνϕʔγϣϯ w ࣾ಺Ͱ1)1ɺ$BLF1)1ͷόʔδϣϯΞοϓʹऔΓ૊Ή͜ͱʹͳΓɺ %PDLFSpMFΛݟͯΈͨɻ w ʮԿʹ࢖ͬͯΔͷ͔෼͔Βͳ͍ύοέʔδ͕ͨ͘͞Μ͋Δʯ w 1)1Ξοϓσʔτ΍%PDLFSΠϝʔδͷܰྔԽΛ΍Ζ͏ʹ΋ɺʢ๻ ࣗ਎͕ʣͲ͔͜Β੾Γ͜Ί͹͍͍͔Θ͔Βͳ͍ঢ়ଶͰ͋ͬͨɻ w

    ʮಉ͡ڥ۰ͷਓͬͯɺ݁ߏ͍ΔΜ͡Όͳ͍͔ͳɾɾʁʯˠτʔΫ ςʔϚʹͯ͠ΈΑ͏ʂ
  7. ͸͡Ίʹ %PDLFSpMFͷಡղྗΛ ͚ͭΔ͖͔͚ͬʹͳΕ͹޾͍Ͱ͢ɻ

  8. ຊฤͷ͸͡·Γɺ͸͡·Γʙ

  9. -FTTPO ʮ·ͣ͸ެࣜͷΠϝʔδΛ஌Ζ͏ʯ

  10. ެࣜͷΠϝʔδΛ஌Ζ͏ օ͞Μ͸ɺ%PDLFSͷΠϝʔδΛ࡞Δ ʹ͋ͨͬͯ࠷ॳʹԿΛ͠·͔͢ɾɾʁ

  11. ެࣜͷΠϝʔδΛ஌Ζ͏

  12. ਖ਼௚ɺ͋·Γྑ͍ํ๏Ͱ͸ͳ͍ ͱߟ͍͑ͯ·͢ɻ

  13. ·ͣ͸ެࣜʢΦϑΟγϟϧʣΛݟͯΈΑ͏ w IUUQTIVCEPDLFSDPN@QIQ w ·ͣ͸৴པͰ͖Δ৘ใʹ͋ͨΔɻ w ҋӢʹΩʔϫʔυݕࡧΛ࢝ΊΔͷ͸ѱखɻ w ৘ใ͕ݹ͔ͬͨΓɺؒҧ͍ͬͯͨΓ΋͢Δ͠ɺʮ݁ہΑ͘෼͔Γ· ͤΜͰͨ͠ʯͰకΊ͘͘Δϒϩά΋͋Δɻ݁Ռతʹ࣌ؒͷແବʹͳ

    ΔՄೳੑ͕ߴ͍ɻ
  14. ެࣜͷ%PDLFS)VCΛݟ͍ͯ͘ w ΫΠοΫελʔτʢ࠷ॳͷҰาʣͷखॱΛ஌Δɻ w Ͳ͏͍ͬͨΠϝʔδ͕͋Δͷ͔ΛνΣοΫͯ͠ɺλάͷҰཡΛோΊͯΈΔɻ w IUUQTHJUIVCDPNEPDLFSMJCSBSZEPDTCMPCNBTUFSQIQ 3&"%.&NETVQQPSUFEUBHTBOESFTQFDUJWFEPDLFSpMFMJOLT w BQBDIFɺGQNBMQJOFɺCVMMTFZFɺ03$DMJ

    CVTUFSFUDɹ w όʔδϣϯɺ04ɺ༻్͝ͱʹ༷ʑͳΠϝʔδ͕͋Γ·͢ɻ
  15. ެࣜͷΠϝʔδΛ஌Ζ͏ ৭ʑ͋Δ͚Ͳ ͲΕΛ࢖ͬͨΒ͍͍ʁ

  16. ࢖༻͢ΔΠϝʔδΛܾΊΔ෼ذ఺ w ϕʔεͷΠϝʔδ͸ԿΛ࢖͍͍ͨʁ w 8FCαʔόʔΛ࢖͏͜ͱΛߟ͍͑ͯΔʁ w ʮ1)1'1.ʯΛ࢖͏͜ͱΛߟ͍͑ͯΔʁ

  17. ॱ൪ʹݟͯΈ·͠ΐ͏

  18. ϕʔεͷΠϝʔδ͸ԿΛ࢖͏͔ w ެࣜͰఏڙ͞Ε͍ͯΔͷ͸ɺʰ%FCJBOʱͱʰ"MQJOF-JOVYʱͷͭɻ w ແ೉ʹਐΊ͍ͨ৔߹͸%FCJBOʹ͢Δͷ͕҆ఆɻ w "MQJOF-JOVY͸΍΍บ͕͋Δɻ˞ޙड़ w ʮ"NB[PO-JOVY͕͍͍ΜͰ͢ʯʮ͹͋ͪΌΜͷҨݴͰ6CVOUV͠ ͔࢖͑ͳ͍ՈܥͳΜͰ͢ʯ

    w ϓϨʔϯͳΠϝʔδΛϕʔεʹ1)1ͷಈ࡞؀ڥΛ࡞Δ͜ͱʹͳΔɻ
  19. 8FCαʔόʔ͕ͳͯ͘΋໰୊ͳ͍৔߹ w ʰWFSTJPODMJʱͷΠϝʔδΛબ୒͢Δɻ w ྫɿDMJCVTUFSɺDMJBMQJOF w 8FCΞϓϦέʔγϣϯΛಈ͔͢ඞཁ͕ͳ͚Ε͹ɺ͜ΕͰ໰୊ͳ͍ɻ w ಛఆͷεΫϦϓτɺόονॲཧͳͲΛ࣮ߦ͍ͨ͠ɻ w

    "84-BNCEBͰ1)1Λಈ͔͍ͨ͠ɻ w ˞"NB[PO-JOVYΛ࢖ͬͨํָ͕͔΋͠Εͳ͍ɻ
  20. 8FCαʔόʔ͕ͳ͍ͱࠔΔ w ʰWFSTJPOBQBDIFʱͷΠϝʔδΛબ୒͢Δɻ w ྫɿBQBDIFCVMMTFZFɺBQBDIF w ΋ͪΖΜɺBQBDIFΛޙ͔ΒೖΕΔ͜ͱ΋ՄೳͰ͢ɻ w ʮͰ΋ɺࢲ͕࢖͍͍ͨͷ͸OHJOYͳΜͰ͕͢ɾɾʯ w

    ެ͕ࣜఏڙ͍ͯ͠ΔϓϦηοτ͸ͳ͍ɻʢͳΜͰ΍ɾɾʣ w OHJOYͷίϯςφΛ࡞ͬͯɺQIQΛಈ͔͍ͯ͠ΔίϯςφʹϦΫΤε τΛඈ͹͢ߏ੒ʹ͢Δͷ͕ͭͷखɻ˞ޙड़
  21. 1)1'1.Λ࢖͍͍ͨ৔߹ w ʰWFSTJPOGQNʱܥͷΠϝʔδΛબ୒͢Δɻ w ྫɿGQNCVMMTFZFɺBMQJOFͳͲ w ͳ͓ɺQIQGQNʹ͸ϦόʔεϓϩΩγ͕ඞཁͳͷͰɺBQBDIF΍ OHJOY͕ඞཁɻ w ʰWFSTJPOGQNʱܥͷΠϝʔδʹBQBDIFͷઃఆ͸ೖͬͯͳ͍৔

    ߹͸ɺࣗલͰ༻ҙ͕ඞཁɻʢΧελϚΠζੑ͕ߴ͍ͱ΋ݴ͑Δʣ
  22. ࣗ෼ʹඞཁͳ΋ͷΛચ͍ग़͠ ద੾ͳελʔτϥΠϯΛ୳ͦ͏

  23. ެࣜͷΠϝʔδΛ஌Ζ͏ ༨ஊɿ"MQJOF-JOVYʹ͍ͭͯ

  24. "MQJOF-JOVYʹ͍ͭͯ

  25. "MQJOF-JOVYʹ͍ͭͯ w NVTMͱCVTZCPYΛϕʔεʹͨ͠-JOVYσΟετϦϏϡʔγϣϯ w #VTZCPY͸૊ΈࠐΈܥͷσΟετϦϏϡʔγϣϯͰɺ"MQJOF-JOVY ΋૊ΈࠐΈܥ޲͖ w BQLͱ͍͏ݻ༗ͷύοέʔδϚωʔδϟʔΛ࢖༻͠·͢ɻ w ೥݄ݱࡏɺόʔδϣϯ͸·Ͱདྷ͍ͯΔɻ

    w ΠϝʔδͷαΠζ͕ʙ.#ఔ౓ͱ͍͏ܰ͞Ͱ͋Δɻ
  26. "MQJOF-JOVYʹ͍ͭͯ w ʮΠϝʔδαΠζ͕খ͍͞ʯͷ͸ྑ͍͜ͱ͕ͩɺ͚ܰͩ͞Ͱ໡໨తʹ ࢖͏ͷ͸ྑ͋͘Γ·ͤΜɻ w ଞͷσΟετϦϏϡʔγϣϯͱ͸ڍಈ͕ҧͬͨΓɺޓ׵ੑʹ͚ܽΔ໘ ͕͋ΔͷͰे෼ͳݕূ͸ඞཁɻ w ࠾༻ΛݟૹͬͨࣄྫɿIUUQTDSFBUPSTOPUFDIBUXPSLDPN FOUSZ

  27. ໨ઌͷ৘ใʹඈͼ͔ͭͣʹ ࣮֬ͳݕূ͕େࣄ

  28. -FTTPO ʮ։ൃ؀ڥΛ࡞ΔྲྀΕΛ௥͏ʯ

  29. ࠓճ૝ఆ͢Δ؀ڥ w 1)1ܥ˞ࠓճ͸%FCJBOܥͷΠϝʔδΛ࢖༻͠·͢ w $BLF1)1Yܥ w 8FMDPNFϖʔδ͕։͚Δͱ͜Ζ·ͰਐΊΔɻ w QIQGQN OHJOY

    w OHJOYͳͷ͸ʰ*46$0/ʱͱ͍͏ΠϕϯτͰ৮Δ͖͔͚͕ͬ૿͔͑ͨ ΒͳΜͱͳ͘Ͱ͢ɻ w ˞಺༰͸(JU)VCͷϦϙδτϦͰڞ༗͠·͢
  30. ΍ͬͯΈͨಈػ w ެࣜΠϝʔδʹ৭ʑࡌ͍ͬͯΔͷ͸ཧղ͕ͨ͠ɺ΍͸Γࣗ෼Ͱ࡞ͬͯ Έͳ͍ͱצ͕௫Ίͳ͍ɻࣗ෼ͷܦݧʹͳΒͳ͍ɻ w ʮ؆୯ʹ࡞ΕΔ΍ΖʂʯˠେମԿ͔͠ΒͰϋϚͬͯ਺༹͔࣌ؒͨ͠ Γ͢Δɻ w ࣗࣾͷϓϩμΫτͰ࢖͍ͬͯΔϑϨʔϜϫʔΫ΁ͷཧղΛਂΊ͍ͨɻ

  31. ඞཁͳաఔΛચ͍ग़͢ w OHJOY͕ಈ࡞͢ΔίϯςφΛ࡞੒ɻ w 1)1ɺQIQGQN͕ಈ࡞͢ΔίϯςφΛ࡞੒ɻ w ίϯςφؒͷ௨৴Λߏ੒͢Δɻ w $BLF1)1ͷॳظΠϯετʔϧΛ࣮ߦ͠ɺެ։༻ͷσΟϨΫτϦΛ OHJOY͔ΒࢀরͰ͖ΔΑ͏ʹ͢Δɻ

  32. ࠓճ૝ఆ͍ͯ͠Δߏ੒ਤ

  33. EPDLFSDPNQPTFZNMͷ಺༰ version: ‘3’ services: nginx: image: nginx:1.21 ports: - 80:80

    volumes: - ./source:/usr/share/nginx/html - ./nginx/default.conf:/etc/nginx/conf.d/default.conf php-fpm: build: ./php-fpm volumes: - ./source:/var/www/html
  34. 1)1༻Πϝʔδͷॳظঢ়ଶ FROM php:8.0-fpm QIQGQN͕࢖͑Δλάɻ ઌఔ৮Εͨ࿩Λݩʹɺ%FCJBOܥΛ࢖༻ɻ

  35. QIQGQN OHJOYͷઃఆ # pass the PHP scripts to FastCGI server

    listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} location ~ \.php$ { root /var/www/html/; fastcgi_pass php-fpm:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } OHJOY΁ͷϦΫΤετ࣌ 1)1ͷίϯςφͱ௨৴͢Δ
  36. ॳճͷૄ௨֬ೝ # index.phpΛҎԼͷΑ͏ʹฤूͯ͠อଘ <?php phpinfo(); ?> IUUQMPDBMIPTU Λ։͍ͨΒ1)1ͷόʔδϣϯΛ֬ೝͰ͖Δ

  37. ͔͜͜Β$BLF1)1Λ ೖΕ͍ͯ͘ύʔτͰ͢

  38. $BLF1)1ͷཁ݅Λ֬ೝ w ϑϨʔϜϫʔΫʹ͸جຊతʹγεςϜཁ͕݅͋ΔͷͰɺΠϯετʔϧΛ ࢝ΊΔલʹཁ݅ΛݟͯΈ·͢ɻ w )551αʔόʔʢ"QBDIFɺNPE@SFXSJUF͕ਪ঑͞ΕΔʣ w 1)1 w NCTUSJOH1)1֦ுɺJOUM1)1֦ுɺTJNQMFYNM1)1֦ு

    w ࢖༻͢ΔσʔλϕʔεʹԠͨ͡1%0֦ுϞδϡʔϧ w ࢀߟIUUQTCPPLDBLFQIQPSHKBJOTUBMMBUJPOIUNM
  39. ·ͣ͸$BLF1)1ͷཁ݅Λ֬ೝ w ϑϨʔϜϫʔΫʹ͸جຊతʹγεςϜཁ͕݅͋ΔͷͰɺ$BLF1)1ͷཁ ݅ΛݟͯΈ·͢ɻ w )551αʔόʔʢ"QBDIFɺNPE@SFXSJUF͕ਪ঑͞ΕΔʣ w 1)1 w NCTUSJOH1)1֦ுɺJOUM1)1֦ுɺTJNQMFYNM1)1֦ு

    w ࢖༻͢ΔσʔλϕʔεʹԠͨ͡1%0֦ுϞδϡʔϧ w ࢀߟIUUQTCPPLDBLFQIQPSHKBJOTUBMMBUJPOIUNM ࠓճͷτʔΫͰ஫໨͍ͨ͠ͷ͸ ͜͜ͷ෦෼ʂ
  40. τʔΫςʔϚΒ͍͠࿩୊͕ ग़͖ͯ·ͨ͠Ͷ

  41. $BLF1)1ʹඞཁͳ֦ுϞδϡʔϧ w $BLF1)1͸ҎԼͷ1)1֦ுϞδϡʔϧΛඞཁͱ͠·͢ɻ w NCTUSJOH1)1֦ு w ϚϧνόΠτରԠͷจࣈྻؔ਺Λఏڙ w JOUM1)1֦ு w

    ࠃࡍԽରԠ༻ͷػೳʢλΠϜκʔϯ΍೔෇ܗࣜͳͲʣΛఏڙ w TJNQMFYNM1)1֦ு w 9.-ΛΦϒδΣΫτͱͯ͠ѻ͏ػೳ w 1%0֦ுϞδϡʔϧ w 1%0ʢ1)1%BUB0CKFDUʣͷ֦ுϞδϡʔϧɻ1)1͔ΒσʔλϕʔεʹΞΫηε͢ΔΠϯλʔϑΣΠεΛఏڙ w ˞࢖༻͢ΔσʔλϕʔεʹԠͨ͡υϥΠό͕ඞཁ
  42. ೖ͍ͬͯΔϞδϡʔϧͷ֬ೝ # php -m [PHP Modules] Core ctype curl date

    dom fileinfo filter ftp … # php -m | grep mbstring Mbstring QIQNͰҰཡදࣔͰ͖Δɻ ಛఆͷϞδϡʔϧ͚ͩ֬ೝ͚ͨ͠Ε͹ɺ HSFQΛซ༻͢Δͷָ͕ɻ
  43. $BLF1)1ʹඞཁͳ֦ுϞδϡʔϧ w NCTUSJOH1)1֦ுˠQIQGQNʹೖͬͯΔ w JOUM1)1֦ுˠೖͬͯͳ͍ͷͰೖΕΔඞཁ͕͋Δɻ w TJNQMFYNM1)1֦ுˠQIQGQNʹೖͬͯΔ w 1%0֦ுϞδϡʔϧˠೖͬͯͳ͍ͷͰೖΕΔඞཁ͕͋Δɻ w

    ˞ࠓճ͸.Z42-Λ࢖͏૝ఆͰ࿩ΛਐΊ·͢ɻ
  44. 1)1༻Πϝʔδɾͦͷ FROM php:8.0-fpm # add extension module RUN docker-php-ext-install pdo_mysql

    intl # docker-php-ext-install͸ެࣜͷPHPΠϝʔδ͕ఏڙ͍ͯ͠Δʮ֦ுϞδϡʔϧૢ࡞πʔϧʯ # ެࣜΠϝʔδΛ࢖͏ϝϦοτͷ1ͭ ֦ுϞδϡʔϧΛΠϯετʔϧ
  45. ࣮ࡍʹ؀ڥΛ࡞ͬͯΈΑ͏ ඞཁͳϞδϡʔϧ͕͜ΕͰἧͬͨʂ

  46. ࣮ࡍʹ؀ڥΛ࡞ͬͯΈΑ͏ ͱࢥΘΕΔ͔΋͠Εͳ͍Ͱ͕͢ɺ ࣮͸·ͩͰ͢

  47. ֦ுϞδϡʔϧʹ΋ཁ͕݅͋Δ w JOUM1)1֦ுͷϏϧυཁ݅ w ͜ͷ֦ுϞδϡʔϧΛϏϧυ͢Δʹ͸{*$6ϥΠϒϥϦͷόʔ δϣϯҎ߱ΛΠϯετʔϧ͢Δඞཁ͕͋Γ·͢ɻ1)1 Ҏ߱͸ɺ*$6Ҏ͕߱ඞཁͰ͢ɻ w IUUQTXXXQIQOFUNBOVBMKBJOUMSFRVJSFNFOUTQIQ

  48. 1)1༻Πϝʔδɾͦͷ FROM php:8.0-fpm RUN apt update RUN apt install -y

    libicu-dev # add extension module RUN docker-php-ext-install pdo_mysql intl ֦ுϞδϡʔϧͷϏϧυʹ࢖༻͢Δ ύοέʔδͷ௥Ճ
  49. 1)1༻Πϝʔδɾ׬੒ܗ FROM php:8.0-fpm RUN apt update RUN apt install -y

    git zip unzip libicu-dev # add extension module RUN docker-php-ext-install pdo_mysql intl # install composer COPY --from=composer:2.0.12 /usr/bin/composer /usr/bin/composer $BLF1)1ຊମͷऔಘ͸ DPNQPTFSʹ೚ͤΔɻ ඞཁͳ΋ͷΛผ్௥Ճɻ
  50. ิ଍OHJOYͷઃఆ location / { root /usr/share/nginx/html/my_app/webroot; index index.html index.htm index.php;

    } location ~ \.php$ { root /var/www/html/my_app/webroot; fastcgi_pass php-fpm:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } $BLF1)1ͷެ։༻σΟϨΫτϦΛࢦఆ
  51. ࢒Γͷ࡞ۀ w OHJOYͷઃఆΛߋ৽͠ɺ$BLF1)1ͷެ։༻σΟϨΫτϦʹ޲͚Δɻ w ׬੒ܗͷ%PDLFSpMFΛݩʹίϯςφΛϏϧυɻ w ίϯςφ಺Ͱ$BLF1)1ͷΠϯετʔϧ w $PNQPTFSDSFBUFQSPKFDUŠQSFGFSEJTUDBLFQIQBQQ 

    NZ@BQQ
  52. ׬੒ʂ

  53. $BLF1)1ͷը໘͕ݟΕΔΑ͏ʹͳΔ·Ͱ w ϕʔεͱͳΔΠϝʔδʢQIQGQNʣΛબͿɻ w $BLF1)1ͷΠϯετʔϧཁ݅Λ֬ೝ͠ɺඞཁͳϞδϡʔϧΛΠϯε τʔϧɾ༗ޮԽ͢Δɻ w Ϗϧυ࣌ͷґଘؔ܎͕͋Ε͹ɺͦΕΛղܾʢJOUMͷ*$6ґଘʣ w ࢀߟIUUQTXXXQIQOFUNBOVBMKBFYUFOTJPOTQIQ

    w $PNQPTFSΛ࢖͑Δঢ়ଶʹ͠ɺ$BLF1)1ΛΠϯετʔϧɻ w OHJOYͷઃఆ
  54. -FTTPO ʮެࣜΠϝʔδͷத਎ΛݟͯΈΑ͏ʯ

  55. ެࣜͷΠϝʔδͷத਎ΛݟͯΈΑ͏ ެࣜͰఏڙ͞Εͯͳ͍ϕʔε Λ࢖͍͍ͨ৔߹͸Ͳ͏͢Δ͔ʁ

  56. ެࣜͷΠϝʔδͷத਎ΛݟͯΈΑ͏

  57. ެࣜΠϝʔδΛಡΜͰΈΔ w 6CVOUV΍"NB[PO-JOVYΛݩʹ1)1ͷಈ࡞؀ڥΛ࡞Δ͜ͱ͸໪࿦Մ ೳͰ͢ɻ w ͔͠͠ɺʮ΍ͬͯΈ·͠ΐ͏ʂʯͱݴΘΕͯ΋Կ͔Β࢝ΊΕ͹͍͍ ͷ͔ࠔΓ·͢ΑͶɾɾɻ w ެࣜͷΠϝʔδΛίʔυϦʔσΟϯάͯ͠ɺԿΛ΍͍ͬͯΔͷ͔Λ ཧղΛਐΊΔͷ͕࣮͸ۙಓʹͳΓ·͢ɻ

  58. ެࣜΠϝʔδΛಡΜͰΈΔ w ୊ࡐɿCVMMTFZF w IUUQTHJUIVCDPNEPDLFSMJCSBSZQIQCMPC EECDFCDEG⒎FECCGBCGF CVMMTFZFDMJ%PDLFSpMF w ΍͍ͬͯΔ಺༰ͷେ·͔ͳྲྀΕΛ௫ΜͰ΋Β͏ͷ͕໨తͳͷͰɺཁ ॴཁॴΛൈਮͯ͠࿩͠·͢ɻ

  59. ࣮ࡍʹಡΜͰΈͨ

  60. FROM debian:bullseye-slim # prevent Debian’s PHP packages from being installed

    RUN set -eux; \ { \ echo ‘Package: php*’; \ echo ‘Pin: release *’; \ echo ‘Pin-Priority: -1’; \ } > /etc/apt/preferences.d/no-debian-php # dependencies required for running “phpize” # (see persistent deps below) ENV PHPIZE_DEPS \ autoconf \ dpkg-dev \ file \ g++ \ gcc \ libc-dev \ make \ pkg-config \ re2c ࠷௿ݶͷ΋ͷ͔͠ೖͬͯͳ͍ ܰྔ൛ΠϝʔδΛϕʔεʹ࢖͏ ʮphp-*ʯͰ࢝·ΔύοέʔδΛ aptͰΠϯετʔϧ͠ͳ͍ઃఆ PHP֦ுϞδϡʔϧͷϏϧυʹ࢖༻ ͢Δphpize͕ґଘ͢ΔύοέʔδΛ వΊͯࢦఆ͍ͯ͠Δ
  61. # persistent / runtime deps RUN set -eux; \ apt-get

    update; \ apt-get install -y --no-install-recommends \ $PHPIZE_DEPS \ ca-certificates \ curl \ xz-utils \ ; \ rm -rf /var/lib/apt/lists/* ENV PHP_INI_DIR /usr/local/etc/php RUN set -eux; \ mkdir -p “$PHP_INI_DIR/conf.d”; \ [ ! -d /var/www/html ]; \ mkdir -p /var/www/html; \ chown www-data:www-data /var/www/html; \ chmod 777 /var/www/html લड़Ͱࢦఆͨ͠phpize༻ͷύοέʔδͱ PHPຊମͷΠϯετʔϧʹ࢖༻͢Δύοέʔδ /var/www/htmlσΟϨΫτϦͷॴ༗ऀ Λwww-dataʹઃఆ͠ɺapacheΛ࣮ߦ Մೳʹ͢Δɻ ※<version>-apacheܥͷΠϝʔδ͸͜ ͷޙʹapacheΛΠϯετʔϧ͢Δɻ iniϑΝΠϧͷஔ͖৔ॴΛ༻ҙ
  62. 1)1ຊମΛΠϯετʔϧ͢Δઃఆ͕ ͠͹Β͘ଓ͘ͷͰதུɾɾ 1)1ຊମͷϏϧυઃఆΛͨ͠Γɺ ιʔείʔυΛXHFUͰऔಘͨ͠Γͯ͠·͢ɻ

  63. COPY docker-php-source /usr/local/bin/ RUN set -eux; \ \ savedAptMark=“$(apt-mark showmanual)“;

    \ apt-get update; \ apt-get install -y --no-install-recommends \ ${PHP_EXTRA_BUILD_DEPS:-} \ libargon2-dev \ libcurl4-openssl-dev \ libonig-dev \ libreadline-dev \ libsodium-dev \ libsqlite3-dev \ libssl-dev \ libxml2-dev \ zlib1g-dev \ PHPͷϏϧυʹ࢖͏ύοέʔδΛΠ ϯετʔϧͭͭ͠ɺʮapt-mark showmanualʯͰΠϯετʔϧͨ͠΋ ͷΛه࿥͍ͯ͠Δɻ PHPίʔυΛల։͢Δ γΣϧεΫϦϓτΛίϐʔ ※ݩͷεΫϦϓτ͸ϦϙδτϦʹ
  64. ./configure \ --build="$gnuArch" \ --with-config-file-path="$PHP_INI_DIR" \ --with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \ \ #

    make sure invalid --configure-flags are fatal errors instead of just warnings --enable-option-checking=fatal \ \ # https://github.com/docker-library/php/issues/439 --with-mhash \ \ # https://github.com/docker-library/php/issues/822 --with-pic \ \ # --enable-ftp is included here because ftp_ssl_connect() needs ftp to be compiled statically (see https://github.com/docker-library/php/issues/236) --enable-ftp \ # --enable-mbstring is included here because otherwise there's no way to get pecl to use it properly (see https://github.com/docker-library/php/issues/195) --enable-mbstring \ ※ ௕͗͢ΔͷͰҰ෦ൈਮ PHPຊମʹؚ·Ε͍ͯΔʮconfigureʯͱ͍͏γΣϧεΫϦϓτΛ࣮ߦɻ Πϯετʔϧʹඞཁͳ΋ͷΛνΣοΫͭͭ͠ɺMakefileΛੜ੒
  65. make -j "$(nproc)"; \ find -type f -name '*.a' -delete;

    \ make install; \ find /usr/local/bin /usr/local/sbin -type f -perm +0111 -exec strip --strip-all '{}' + || true; \ make clean; \ \ # https://github.com/docker-library/php/issues/692 (copy default example "php.ini" files somewhere easily discoverable) cp -v php.ini-* "$PHP_INI_DIR/"; \ \ cd /; \ docker-php-source delete; \ PHP͔ΒॳظͷiniϑΝΠϧʢphp.ini.production ͳͲʣΛίϐʔͭͭ͠ɺϏϧυΛऴ͑ͯෆཁ ʹͳͬͨPHPͷιʔείʔυΛফ͢ɻ લͷ޻ఔͰੜ੒ͨ͠makefileΛ࣮ߦͱ૟আ
  66. # reset apt-mark's "manual" list so that "purge --auto-remove" will

    remove all build dependencies apt-mark auto '.*' > /dev/null; \ [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; \ find /usr/local -type f -executable -exec ldd '{}' ';' \ | awk '/=>/ { print $(NF-1) }' \ | sort -u \ | xargs -r dpkg-query --search \ | cut -d: -f1 \ | sort -u \ | xargs -r apt-mark manual \ ; \ apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \ rm -rf /var/lib/apt/lists/*; \ Ϗϧυʹ࢖͍ͬͯͨύοέʔδ͸͜ͷλΠϛϯάͰඞཁͳ͘ͳ ΔͷͰফ͢ɻʮapt-mark showmanualʯͰΠϯετʔϧͨ͠΋ͷΛ ه࿥͍ͯͨ͠ͷ͸ɺ͜ͷ࣌ͷͨΊɻ
  67. ۦ͚଍Ͱ͕ͨ͠ɺ େ·͔ͳྲྀΕ͸Ҏ্Ͱ͢

  68. ެࣜΠϝʔδͰ΍͍ͬͯΔ͜ͱ w ܰྔ൛ΠϝʔδͰ͋ΔɺEFCJBOCVMMTFZFTMJNΛϕʔεʹ͢Δɻ w 1)1ຊମͷϏϧυɺ1)1ͷ֦ுϞδϡʔϧΛϏϧυͷͨΊͷύοέʔδΛΠϯε τʔϧ͢Δɻ w 1)1ຊମΛΠϯετʔϧ͢Δɻ w %PDLFSpMFͰ͸ιʔείʔυΛXHFUͰऔಘ͍ͯ͠Δ͕ɺʮBQUHFUQIQʯ

    ͰೖΕͯ΋໰୊ͳ͍ɻ w ઃఆϑΝΠϧΛ1)1͔Β࣋ͬͯ͘Δɻ w ϏϧυΛҰ௨Γऴ͑ͨΒɺϏϧυ༻ͷύοέʔδΛফ͢ɻ
  69. େ·͔ͳྲྀΕΛ ࣗ෼Ͱ࠶ݱ͢Ε͹0,

  70. ࠓ೔࿩͔ͨͬͨ͠಺༰͸ ͜Μͳͱ͜ΖͰ͢

  71. ·ͱΊ

  72. ·ͱΊ w ҋӢʹݕࡧͤͣʹɺ·ͣ͸ެࣜͷ%PDLFSΠϝʔδΛݟΔɻ w ࣗ෼ͷ໨తʢϕʔεͷ04ɺQIQGQN΍8FCαʔόʔͷ༗ແʣΛݩʹ ༻ҙ͞ΕͨΠϝʔδ͔Βબͼ·͠ΐ͏ɻ w "MQJOFΛ࢖͍͍ͨ৔߹͸࣮֬ͳݕূΛɻ w ࣗ෼ͰΠϝʔδΛ૊Έཱ͍ͯͨ৔߹ɺ࣮ࡍʹखΛಈ͔ͯ͠׳ΕͯΈΔ

    ͷ͕ॏཁͳୈҰาͱͳΔɻ
  73. %PDLFSpMFΛಡΉࡍͷࢀߟϦϯΫ • PHP֦ுϞδϡʔϧͷҰཡ • https://www.php.net/manual/ja/extensions.alphabetical.php • PECL֦ுϞδϡʔϧΛPHPʹ૊ΈࠐΉ • https://www.php.net/manual/ja/install.pecl.static.php •

    PhpizeͰPECL֦ுϞδϡʔϧΛಡΈࠐΉ • https://www.php.net/manual/ja/install.pecl.phpize.php • ୊ࡐͱͨ͠Dockerfileʢdebian-bullseyeʣ • https://github.com/docker-library/php/blob/8d98db4cebcdf5ff776e2d0b9bf4a5b482f4e657/8.0/ bullseye/cli/Dockerfile
  74. ·ͱΊ ʢ܁Γฦ͠ʹͳΓ·͕͢ʣ %PDLFSpMFΛཧղ͢Δ͖͔͚ͬ ʹͳΕ͹޾͍Ͱ͢ɻ

  75. ൃදʹର͢ΔϑΟʔυόοΫ͸ େ׻ܴͰ͢ʂ

  76. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ