Docker入門

Software

shinichiro-ohhara
The present document can't read!
Please download to view
31
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Description
勉強会の資料です。
塩尻インキュベーションプラザ、松本ソフト開発センター、にてオープンな勉強会を実施しています。
Text
  • 1. Docker ධ㛛䝁䞁䝔䝘⟶⌮䝅䝇䝔䝮
  • 2. ⮬ᕫ⤂௓኱ཎ ៅ୍㑻䚷https://twitter.com/ohhara_shiojiri䠄᭷䠅䝖䝷䝇䝖䝛䝑䝖䝽䞊䜽䝇䚷ሷᑼ䜲䞁䜻䝳䝧䞊䝅䝵䞁䝥䝷䝄䠍䠌䠔ྕᐊhttp://shiojiri-osslabo.com/䞉㛗㔝┴ሷᑼᕷ䛻άືᣐⅬ䜢⨨䛟䚸ᕷෆ䝥䝻䜾䝷䝬䞊᭷ᚿ䛻䜘䜛ᅋయ䞉䛂䜸䞊䝥䞁䛺⎔ቃ䛷䜸䞊䝥䞁䛺άື䜢┠ᣦ䛩䛃䜢ྜゝⴥ䛻㞟䛖䞉CoderDojo Shiojiri 㛤ദ䚷䞉ᑠᏛ⏕㧗Ꮫᖺྥ䛡Rubyᩍᐊ㛤ദ䞉ITᢏ⾡᭩䜢䝸䝤䝷䜲䝈䛷㈚䛧ฟ䛧䚸䜎䛯ᕷ❧ᅗ᭩㤋䛸༠ຊ
  • 3. 䜰䝆䜵䞁䝎● Docker䛻䛴䛔䛶● 䝁䞁䝔䝘ᆺ䛾௬᝿໬⎔ቃ● ᕪศ⟶⌮䝅䝇䝔䝮● 䜲䞁䝇䝖䞊䝹᪉ἲ● 䝁䞁䝔䝘䛾㉳ື● 䝁䞁䝔䝘䛸䜲䝯䞊䝆䛾๐㝖● 䝃䞊䝡䝇䜢䝁䞁䝔䝘䛷㉳ື● Dockerfile● 䝺䝆䝇䝖䝸
  • 4. Docker䛻䛴䛔䛶● https://www.docker.com/● ึ∧䛿2013ᖺ3᭶13᪥● ᭱᪂∧䛿䚸1.2.0(2014ᖺ9᭶12᪥᫬Ⅼ)● 㛤Ⓨ⪅䠖Solomon HykesẶ● Docker♫(ᪧdotCloud♫䛿2013ᖺ10᭶29᪥䛻♫ྡኚ᭦)䛻䛶㛤Ⓨ● 㛤Ⓨゝㄒ䠖Go● ືస⎔ቃ䠖Linux䜹䞊䝛䝹2.6.32௨㝆 64bit● 䝷䜲䝉䞁䝇䠖Apache License 2.0
  • 5. 䝁䞁䝔䝘ᆺ䛾௬᝿໬⎔ቃ● 䝝䜲䝟䞊䝞䜲䝄䞊ᆺ○ VirtualBox䜔VMWare䛺䛹䚹○ 䠍ྎ䛾䝁䞁䝢䝳䞊䝍䞊ୖ䛻」ᩘ䛾䝁䞁䝢䝳䞊䝍䞊䜢䜶䝭䝳䝺䞊䝖䠄௬᝿໬䠅䛧䜎䛩䚹○ 䝞䞊䝏䝱䝹䝬䝅䞁(VM)䛸࿧⛠䛥䜜䜎䛩䚹○ ᵝ䚻䛺OS⎔ቃ䜢䝁䞁䝢䝳䞊䝍䞊䝸䝋䞊䝇䛜䛒䜛㝈䜚䚸」ᩘ✌ാ䛷䛝䜎䛩䚹○ 䝁䞁䝢䝳䞊䝍䞊䝸䝋䞊䝇䛾ຠ⋡໬䛜ᅗ䜜䜛䚹○ 䝝䞊䝗䜴䜵䜰䜢䜶䝭䝳䝺䞊䝖䛩䜛Ⅽ䚸䜸䞊䝞䞊䝦䝑䝗䛜Ⓨ⏕䛩䜛ศ䚸VM⮬య䛾㏿ᗘ䛿䝩䝇䝖ഃ䜘䜚పୗ䛩䜛䚹○ 䝁䞁䝢䝳䞊䝍䞊䝸䝋䞊䝇䛾㓄ศ䛜ᅛᐃ໬䛥䜜䜛䚹
  • 6. 䝁䞁䝔䝘ᆺ䛾௬᝿໬⎔ቃ● 䝁䞁䝔䝘ᆺ○ Linux䜹䞊䝛䝹䛻APIᐇ⿦䛥䜜䛶䛔䜛䚹○ 0.9௨๓䛿LXC(Linux Containers)䛻౫Ꮡ䛧䛶䛔䜎䛧䛯䚹○ 䜰䝥䝸䜿䞊䝅䝵䞁ືస⎔ቃ䛰䛡䜢ᢳ㇟໬䛧䛶䛔䜛䚹○ 䝝䞊䝗䜴䜵䜰䛸䜹䞊䝛䝹䛿䝩䝇䝖ഃ䛸ඹ᭷䛩䜛䚹○ 䝝䞊䝗䜴䜵䜰䜢䜶䝭䝳䝺䞊䝖䛧䛺䛔Ⅽ䚸䜸䞊䝞䞊䝦䝑䝗䛜Ⓨ⏕䛧䛺䛔䛾䛷䚸VM䜘䜚㧗㏿䛻ືస䛩䜛䚹○ 䝁䞁䝢䝳䞊䝍䞊䝸䝋䞊䝇䜒ඹ᭷䛺䛾䛷ᅛᐃ໬䛥䜜䛺䛔䚹○ VM䛷䛿↓䛔䛾䛷䚸Linux௨እ䛾OS䛿ືస䛧䛺䛔䚹○ 䝃䞊䝞䞊䛾VM䛷✌ാ䛥䛫䛶䛔䜛䛾䛿LAMP⎔ቃ䜀䛛䜚䛺䛾䛷䚸VM䛾ᚲせᛶ䛜↓䛔䜽䝷䜴䝗⎔ቃ䛷ὀ┠䛥䜜䛶䛔䜛䚹
  • 7. ᕪศ⟶⌮䝅䝇䝔䝮● AUFS (Another Unionfs)○ ㏱㐣ⓗ䛻䝣䜯䜲䝹䝅䝇䝔䝮䜢⟶⌮䛷䛝䜎䛩䚹○ LiveCD䛻䛶䝯䝰䝸✵㛫䜢᭩䛝᥮䛘ྍ⬟㡿ᇦ䛸䛧䛶฼⏝䛩䜛᪉ἲ䛸䛧䛶౑䜟䜜䛶䛔䜎䛩䚹● ᕪศ⟶⌮○ 䝣䜯䜲䝹⟶⌮䛻AUFS䜢౑⏝䛧䛶䛔䜛䚹○ AUFS䛾ㄞ᭩ᒓᛶ䛾ኚ᭦䜢฼⏝䛧䛶䛔䜛䚹○ 䝁䞁䝔䝘䛾㉳ື䜔ኚ᭦ẖ䛻ᒙ䠄䝺䜲䝲䞊䠅⟶⌮○ ኚ᭦䛰䛡䜢ಖᏑ䛩䜛䚹○ 㔜」䛩䜛↓㥏䛜Ⓨ⏕䛧䛺䛔䚹
  • 8. 䜲䞁䝇䝖䞊䝹᪉ἲ● Linux⎔ቃ䛾䛒䜛ሙྜ○ Ubuntu䛾ሙྜ■ 12.04LTS௨㝆64bit∧䛻䛶ᑐᛂ䛧䛶䛔䜎䛩䚹○ CentOS䛾ሙྜ■ 6.5௨㝆64bit∧䛻䛶ᑐᛂ䛧䛶䛔䜎䛩䚹● Windows䜔MacOS䛾ሙྜ○ VirtualBox䛷Linux䜢✌ാ䛥䛫䛶౑⏝䛧䜎䛩䚹○ ᑓ⏝䛾䝕䜱䝇䝖䝸䝡䝳䞊䝅䝵䞁䛂boot2docker䛃䛜䛒䜚䜎䛩䚹○ https://github.com/boot2docker/boot2docker/releases
  • 9. 䜲䞁䝇䝖䞊䝹᪉ἲ● Ubuntu䛾ሙྜ○ ⨜䠍䠖ྠ䛨ྡ⛠䛾ู䛺䝟䝑䜿䞊䝆䛜䛒䜛䚹■ apt-get install docker○ ⨜䠎䠖ᶆ‽䝟䝑䜿䞊䝆䛾䝞䞊䝆䝵䞁䛜ྂ䛔(0.9)■ apt-get install docker.io○ බᘧ䝗䜻䝳䝯䞁䝖䜢ཧ↷■ http://docs.docker.com/installation/ubuntulinux/○ 䜲䞁䝇䝖䞊䝹⏝䛾䝇䜽䝸䝥䝖䛜⏝ព䛥䜜䛶䛔䜎䛩䚹■ curl -sSL https://get.docker.io/ubuntu/ | sudo sh○ 䝞䞊䝆䝵䞁䜢☜ㄆ䛧䛶䜏䜎䛩䚹■ docker version
  • 10. 䜲䞁䝇䝖䞊䝹᪉ἲ● rootᶒ㝈○ 䝋䜿䝑䝖䝣䜯䜲䝹(/var/run/docker.sock)䛿୍⯡䝴䞊䝄䞊䛻᭩䛝㎸䜏ᶒ㝈䛜↓䛔Ⅽ䚸docker䝁䝬䞁䝗䛻rootᶒ㝈䛜ᚲせ䛻䛺䜚䜎䛩䚹○ docker䜾䝹䞊䝥䛻䛿䚸᭩䛝㎸䜏ᶒ㝈䛜௜୚䛥䜜䛶䛔䜛䛾䛷䚸䝴䞊䝄䞊䜢docker䜾䝹䞊䝥䛻㏣ຍ䛩䜛஦䛷䚸sudo䝁䝬䞁䝗䛜୙せ䛻䛺䜚䜎䛩䚹○ sudo gpasswd -a user docker■ -a 䝴䞊䝄䞊ྡ䠄䛣䛣䛷䛿user䠅䜢ᣦᐃ䛩䜛䚹○ ෌䝻䜾䜲䞁䛩䜛஦䛷᭷ຠ䛻䛺䜛䚹
  • 11. 䜲䞁䝇䝖䞊䝹᪉ἲ● CentOS䛾ሙྜ○ CentOS 7䛾ሙྜ■ yum install docker○ CentOS 6䛾ሙྜ■ EPEL䝸䝫䝆䝖䝸䛻䝟䜿䞊䝆䛜䛒䜚䜎䛩䚹■ yum install docker-io■ service docker start■ chkconfig docker on○ බᘧ䝗䜻䝳䝯䞁䝖䜢ཧ↷■ https://docs.docker.com/installation/centos/○ 䝞䞊䝆䝵䞁䜢☜ㄆ䛧䛶䜏䜎䛩䚹■ docker version
  • 12. 䝁䞁䝔䝘䛾㉳ື● 䝁䞁䝔䝘䜲䝯䞊䝆○ 䝁䞁䝔䝘䛾ඖ䛻䛺䜛䜲䝯䞊䝆䛜䝔䞁䝥䝺䞊䝖䛸䛧䛶බ㛤䛥䜜䛶䛔䜎䛩䚹■ https://registry.hub.docker.com/○ 䝕䜱䝇䝖䝸䝡䝳䞊䝅䝵䞁ẖ䛻ᵝ䚻䛺䜲䝯䞊䝆䛜䛒䜚䜎䛩䚹○ 䝎䜴䞁䝻䞊䝗䛧䛯䜲䝯䞊䝆䛿䚸䝻䞊䜹䝹䜻䝱䝑䝅䝳䛷෌฼⏝䛷䛝䜎䛩䚹○ 䝣䜯䜲䝹䛾ᕪศ䛛䜙ู䛾䜲䝯䞊䝆䜢సᡂ䛷䛝䜎䛩䚹○ సᡂ䛧䛯䜲䝯䞊䝆䜢୍⯡䛻බ㛤䛷䛝䜎䛩䚹○ ඹྠ㛤Ⓨ⪅䛸సᡂ䛧䛯䜲䝯䞊䝆䜢ඹ᭷฼⏝䛷䛝䜎䛩䚹○ ␗䛺䜛䜽䝷䜴䝗䝃䞊䝡䝇㛫䛷䜒ඹ㏻䛻฼⏝䛷䛝䜎䛩䚹
  • 13. 䝁䞁䝔䝘䛾㉳ື● docker pull○ 䝁䞁䝔䝘䜲䝯䞊䝆䜢䝎䜴䞁䝻䞊䝗䛧䜎䛩䚹○ 䜸䝥䝅䝵䞁䛻䜲䝯䞊䝆ྡ䛸䝍䜾ྡ䜢䛂䠖䛃䛷ᣦᐃ䛧䜎䛩䚹■ docker pull ubuntu:latest○ 䜸䝸䝆䝘䝹䜲䝯䞊䝆䛾ሙྜ䚸䜲䝯䞊䝆ྡ䛻ຍ䛘䛶䝴䞊䝄䞊ྡ䜢䛂䠋䛃䛷༊ษ䛳䛶௜䛡䜛䚹■ docker pull user/ubuntu:latest○ 䝍䜾ྡ䛷䝞䞊䝆䝵䞁ᣦᐃฟ᮶䜎䛩䛜䚸┬␎᫬䛩䜛䛸᭱᪂∧䠄latest䠅䛾ᣦᐃ䛻䛺䜚䜎䛩䚹■ docker pull ubuntu:14.04● docker images䝻䞊䜹䝹䜻䝱䝑䝅䝳䛻䛒䜛䜲䝯䞊䝆䛾୍ぴ⾲♧䚹
  • 14. 䝁䞁䝔䝘䛾㉳ື● docker run○ 䜲䝯䞊䝆䛛䜙䝁䞁䝔䝘䜢㉳ື䛧䜎䛩䚹○ docker run -i -t ubuntu /bin/bash■ -i䚷䜲䞁䝍䝷䜽䝔䜱䝤䝰䞊䝗䛷㉳ື䛩䜛䚹■ -t䚷tty➃ᮎ䜲䞁䝍䞊䝣䜵䞊䝇䛷㉳ື䛩䜛䚹■ 䜲䝯䞊䝆ྡ䛿ubuntu䚸䝍䜾ྡ䛿┬␎䛷䛝䜎䛩䚹■ bash䜢ᐇ⾜䛧䛶䝻䜾䜲䞁䛩䜛䚹○ 䝔䝇䝖⏝䛻ఱ䛛䝣䜯䜲䝹䜢సᡂ䛧䛶䜏䜎䛩䚹■ touch /tmp/test.txt○ ⤊஢䛩䜛䛻䛿䚸䛂Ctrl䛃䠇䛂D䛃䜻䞊䛛exit䝁䝬䞁䝗○ 䝥䝻䝉䝇䛾⤊஢䛻క䛳䛶䚸䝁䞁䝔䝘䜒೵Ṇ䛧䜎䛩䚹
  • 15. 䝁䞁䝔䝘䛾㉳ື● docker ps○ 䝁䞁䝔䝘䛾୍ぴ⾲♧䛧䜎䛩䚹○ ೵Ṇ䛧䛯䝁䞁䝔䝘䛿-a䜸䝥䝅䝵䞁䜢௜䛡䜛䚹■ docker ps -a○ ᒚṔ䛸䛧䛶ᕪศ䛷฼⏝䛧䜎䛩䚹● ෌㉳ື○ 䜒䛖୍ᗘ䝁䞁䝔䝘䜢㉳ື䛧䛶䜏䜎䛩䚹■ docker run -i -t ubuntu /bin/bash○ ๓ᅇ䝔䝇䝖⏝䛻సᡂ䛧䛯䝣䜯䜲䝹䜢☜ㄆ䛧䛶䜏䜎䛩䚹■ ls /tmp -l○ 䝁䞁䝔䝘䛿䜲䝯䞊䝆䛾ึᮇ≧ែ䛾䜎䜎䛷䛩䚹○ ඖ䛾䜲䝯䞊䝆䛿ኚ᭦䛥䜜䜎䛫䜣䚹
  • 16. 䝁䞁䝔䝘䛾㉳ື● docker start○ ೵Ṇ䛧䛯䝁䞁䝔䝘䜢෌ᐇ⾜䛧䜎䛩䚹○ 䝁䞁䝔䝘䛾୍ぴ⾲♧䛧䜎䛩䚹■ docker ps -a○ 䝁䞁䝔䝘䛜ᒚṔ䛸䛧䛶䠎䛴⾲♧䛥䜜䜎䛩䚹○ ᭱ึ䛾䝁䞁䝔䝘䜢෌ᐇ⾜䛧䛶䜏䜎䛩䚹■ docker start -i a9876543210■ -i 䝅䜵䝹฼⏝䛩䜛ሙྜ䛿䜲䞁䝍䝷䜽䝔䜱䝤䝰䞊䝗○ ๓ᅇ䝔䝇䝖⏝䛻సᡂ䛧䛯䝣䜯䜲䝹䜢☜ㄆ䛧䛶䜏䜎䛩䚹■ ls /tmp -l○ ኚ᭦䛧䛯䝁䞁䝔䝘䛷䛒䜛䛣䛸䜢☜ㄆฟ᮶䜎䛩䚹
  • 17. 䝁䞁䝔䝘䛾㉳ື● docker commit○ 䝁䞁䝔䝘䛛䜙䜲䝯䞊䝆䜢సᡂ䛧䜎䛩䚹■ docker commit a9876543210 user/ubuntu○ ๓ᅇ䝔䝇䝖⏝䛻䝣䜯䜲䝹䜢సᡂ䛧䛯䝁䞁䝔䝘䛛䜙䜲䝯䞊䝆䜢సᡂ䛧䛶䜏䜎䛩䚹○ 䜲䝯䞊䝆䛜సᡂฟ᮶䛯䜙䚸୍ぴ⾲♧䛧䛶☜ㄆ䛧䜎䛩䚹■ docker images○ సᡂ䛧䛯䜲䝯䞊䝆䛛䜙䝁䞁䝔䝘䜢㉳ື䛧䜎䛩䚹■ docker run -i -t user/ubuntu /bin/bash○ ๓ᅇ䝔䝇䝖⏝䛻సᡂ䛧䛯䝣䜯䜲䝹䜢☜ㄆ䛧䛶䜏䜎䛩䚹■ ls /tmp -l○ 䜲䝯䞊䝆䛜᭦᪂䛥䜜䛯஦䛜☜ㄆฟ᮶䜎䛩䚹
  • 18. 䝁䞁䝔䝘䛸䜲䝯䞊䝆䛾๐㝖● docker rm○ 䝁䞁䝔䝘䜢๐㝖䛧䜎䛩䚹○ 䝔䝇䝖⏝䛻౑⏝䛧䛯䝁䞁䝔䝘䜢๐㝖䛧䛶䜏䜘䛖䚹■ docker ps -a■ docker rm a9876543210■ docker ps -a● docker rmi○ 䜲䝯䞊䝆䜢๐㝖䛧䜎䛩䚹○ 䝔䝇䝖⏝䛻సᡂ䛧䛯䜲䝯䞊䝆䜢๐㝖䛧䛶䜏䜘䛖䚹■ docker images■ docker rmi user/ubuntu■ docker images
  • 19. 䝃䞊䝡䝇䜢䝁䞁䝔䝘䛷㉳ື● 䝃䞊䝡䝇䛾䜲䝯䞊䝆䜢సᡂ○ ౛䛸䛧䛶web䝃䞊䝞䞊䛾nginx䝃䞊䝡䝇⏝䜲䝯䞊䝆䜢సᡂ䛧䛶䜏䜎䛩䚹○ ඖ䛻䛺䜛䝁䞁䝔䝘䜢㉳ື䛧䜎䛩䚹■ docker run -i -t ubuntu /bin/bash○ 䝁䞁䝔䝘ෆ䛷nginx䜢䜲䞁䝇䝖䞊䝹䛧䜎䛩䚹■ apt-get update■ apt-get install -y nginx○ 䝁䞁䝔䝘䜢೵Ṇ䛧䛯ᚋ䚸䜲䝯䞊䝆䜢సᡂ䛧䜎䛩䚹■ docker ps -a■ docker commit b9876543210 nginx/ubuntu■ docker images
  • 20. 䝃䞊䝡䝇䜢䝁䞁䝔䝘䛷㉳ື● 䝞䝑䜽䜾䝷䜴䞁䝗䛷䝁䞁䝔䝘䜢㉳ື○ సᡂ䛧䛯䜲䝯䞊䝆䜢䝃䞊䝡䝇䛸䛧䛶䝞䝑䜽䜾䝷䜴䞁䝗䛷㉳ື䛥䛫䜎䛩䚹○ docker run -d -p 80:80 nginx/ubuntu /usr/sbin/nginx -g 'daemon off;' -c /etc/nginx/nginx.conf■ -d 䝞䝑䜽䜾䝷䜴䞁䝗㉳ື䜸䝥䝅䝵䞁■ -p 䝩䝇䝖ഃ䛸䝁䞁䝔䝘ഃ䛾䝫䞊䝖㌿㏦䜸䝥䝅䝵䞁■ 䝁䞁䝔䝘ෆ䛷䛿䝣䜷䜰䜾䝷䜴䞁䝗䛷✌ാ䛥䛫䛺䛔䛸೵Ṇ䛧䛶䛧䜎䛖䛾䛷䚸nginx䛾䝕䞊䝰䞁ືస䜢↓ຠ໬䛧䛶䛔䜎䛩䚹
  • 21. 䝃䞊䝡䝇䜢䝁䞁䝔䝘䛷㉳ື● 䝁䞁䝔䝘䛾䝃䞊䝡䝇䜢☜ㄆ○ 䝁䞁䝔䝘䛾୍ぴ䜢☜ㄆ䛧䛶䜏䜎䛩䚹■ docker ps○ 䝩䝇䝖ഃ䛾80␒䝫䞊䝖䛻䝃䞊䝡䝇䛜✌ാ䛧䛶䛔䜛஦䜢☜ㄆ䛧䛶䜏䜎䛩䚹■ curl localhost:80■ web䝤䝷䜴䝄䛷nginx䛾䝕䝣䜷䝹䝖䝨䞊䝆䛜⾲♧䛥䜜䜎䛩䚹
  • 22. 䝃䞊䝡䝇䜢䝁䞁䝔䝘䛷㉳ື● 䝁䞁䝔䝘䛾೵Ṇ䛸෌ᐇ⾜○ 䝁䞁䝔䝘䜢೵Ṇ䛧䛶䜏䜎䛩䚹■ docker ps■ docker stop c987654321■ docker ps -a■ curl localhost:80○ ೵Ṇ䛧䛯䝁䞁䝔䝘䜢෌ᐇ⾜䛧䛶䜏䜎䛩䚹■ docker ps -a■ docker start c9876543210■ docker ps■ curl localhost:80
  • 23. Dockerfile● 䜲䝯䞊䝆సᡂ䛻䛚䛡䜛ၥ㢟Ⅼ○ 䝁䞁䝔䝘䛾ᵓᡂ䛻䛴䛔䛶䛾グ㘓䛜ḧ䛧䛔䚹○ 」ᩘ䛾䝁䝬䞁䝗䜢ᐇ⾜䛧䛺䛡䜜䜀䛺䜙䛺䛔䚹○ ᡭືసᡂ䛩䜛㐣⛬䛷䝭䝇䜢㑊䛡䜙䜜䛺䛔䚹● Dockerfile○ సᡂ䛩䜛䝁䞁䝔䝘䛾ᵓᡂ䜢グ㏙䛩䜛䚹○ 䠍⾜䛻䛴䛝䠍䛴䛾ᣦ♧䛷䚸㡰␒䛻ᐇ⾜䛥䜜䜎䛩䚹○ 䛂䠀䛃䛷䝁䝯䞁䝖䜒グ㏙ฟ᮶䜛䚹○ Dockerfile䜢౑⏝䛧䛶䜲䝯䞊䝆䜢⮬ືసᡂ䛩䜛஦䛜ฟ᮶䜛䚹
  • 24. Dockerfile● 䜲䝯䞊䝆䛾⮬ືసᡂ○ nginx䝃䞊䝡䝇䛾䜲䝯䞊䝆䜢⮬ືసᡂ䛧䛶䜏䜎䛩䚹○ 㐺ᙜ䛺ሙᡤ䛷䚸Dockerfile䜢సᡂ䛧䜎䛩䚹■ mkdir docker docker/nginx■ cd docker/nginx■ vi Dockerfile# FROM ඖ䜲䝯䞊䝆ྡFRON ubuntu# RUN 䝁䞁䝔䝘ෆ䛷䛾ᐇ⾜䝁䝬䞁䝗RUN apt-get updateRUN apt-get install -y nginx# ENTRYPOINT䚷䝁䞁䝔䝘䛾ᐇ⾜䝁䝬䞁䝗ENTRYPOINT /usr/sbin/nginx -g 'daemon off;' -c /etc/nginx/nginx.conf
  • 25. Dockerfile● docker build○ Dockerfile䛛䜙䜲䝯䞊䝆䜢సᡂ䛧䜎䛩䚹○ docker build -t nginx/ubuntu:1.0 .■ -t సᡂ䛩䜛䜲䝯䞊䝆ྡ䛸䝍䜾ྡ䜢䛂䠖䛃䛷ᣦᐃ䛩䜛䚹■ Dockerfile䛾ሙᡤ䜢ᣦᐃ䛩䜛䚹■ 䛣䛣䛷䛿䜹䝺䞁䝖䝕䜱䝺䜽䝖䝸䛂䠊䛃䛷ᣦᐃ䚹○ Dockerfile䛾グ㏙㏻䜚䛻䚸ඖ䜲䝯䞊䝆䛛䜙䝁䞁䝔䝘䜢㉳ື䛧䛶䚸nginx䛜䜲䞁䝇䝖䞊䝹䛥䜜䜎䛩䚹○ 䝁䞁䝔䝘䛛䜙ᣦᐃ䛧䛯ྡ⛠䛾䜲䝯䞊䝆సᡂ䜎䛷୍ᗘ䛻ᐇ⾜䛥䜜䜎䛩䚹○ ౑⏝䛥䜜䛯䝁䞁䝔䝘䛿๐㝖䛥䜜䛶ṧ䜚䜎䛫䜣䚹
  • 26. Dockerfile● 䜲䝯䞊䝆䛾☜ㄆ○ ⮬ືసᡂ䛥䜜䛯䜲䝯䞊䝆䜢౑⏝䛧䛶䚸nginx䝃䞊䝞䞊䛾䝃䞊䝡䝇䝁䞁䝔䝘䜢㉳ື䛧䛶䜏䜎䛧䜗䛖䚹○ docker images○ docker ps○ docker run -d -p 80:80 nginx/ubuntu:1.0○ 䝁䞁䝔䝘䛾ᐇ⾜䝁䝬䞁䝗䜢┬␎䛧䛶㉳ື䛷䛝䜛䚹○ docker ps○ curl localhost:80
  • 27. 䝺䝆䝇䝖䝸● 䝺䝆䝇䝖䝸○ 䝁䞁䝔䝘䛾䜲䝯䞊䝆䜢ඹ᭷⟶⌮䛩䜛௙⤌䜏䚹○ 䜲䝯䞊䝆䛿ᵓᡂ᝟ሗ䛸ඹ䛻༢୍䛾䝸䝫䝆䝖䝸䛸䛧䛶ᢅ䜟䜜䜛䚹○ ᶆ‽䛷䛿බᘧ䛾䛂Docker Hub䛃䛜タᐃ䛥䜜䛶䛔䜛䚹○ බᘧ䛾䝸䝫䝆䝖䝸䠄䜲䝯䞊䝆䝔䞁䝥䝺䞊䝖䠅䛾㓄ᕸඖ䛷䛩䚹○ 䝥䝷䜲䝧䞊䝖䛾䝺䝆䝇䝖䝸䜒ᵓ⠏ฟ᮶䜛䚹○ 䠎䛴䛾Ⓩ㘓᪉ἲ䛜䛒䜛䚹■ 䝻䞊䜹䝹䛾䝸䝫䝆䝖䝸䜢┤᥋䜰䝑䝥䝻䞊䝗䛩䜛䚹■ Dockerfile䛛䜙⮬ື⏕ᡂ䛧䛶Ⓩ㘓䛩䜛䚹
  • 28. 䝺䝆䝇䝖䝸● docker login○ බᘧ䝺䝆䝇䝖䝸䛂Docker Hub䛃䛻䝴䞊䝄䞊Ⓩ㘓䛧䜎䛩䚹■ https://docker.com/■ 䝥䝷䜲䝧䞊䝖䝸䝫䝆䝖䝸䠍䛴䜎䛷䛿↓ᩱ○ 䝴䞊䝄䞊Ⓩ㘓䛧䛯䜰䜹䜴䞁䝖䛸䝟䝇䝽䞊䝗䛚䜘䜃䝯䞊䝹䜰䝗䝺䝇䛷䝻䜾䜲䞁ฟ᮶䜎䛩䚹○ 䝻䜾䜲䞁≧ἣ䜢docker info䛷☜ㄆ䛧䛶䜏䜎䛩䚹● docker info○ Docker䛾⎔ቃ᝟ሗ䜢⾲♧䛧䜎䛩䚹○ Username䛸Registry䛷䝺䝆䝇䝖䝸䛜☜ㄆฟ᮶䜎䛩䚹○ 䝞䞊䝆䝵䞁⾲♧䛥䜜䜎䛩䚹
  • 29. 䝺䝆䝇䝖䝸● docker push○ බᘧ䝺䝆䝇䝖䝸䛂Docker HUB䛃䛻䝸䝫䝆䝖䝸䜢Ⓩ㘓䛧䜎䛩䚹○ Ⓩ㘓䛧䛯䝴䞊䝄䞊䜰䜹䜴䞁䝖ྡ䜢䛂䠋䛃䛷ᣦᐃ䛩䜛䚹■ docker push docker_user/repository○ 䝥䝷䜲䝧䞊䝖䝺䝆䝇䝖䝸䛾ሙྜ䛿䚸䝴䞊䝄䞊䜰䜹䜴䞁䝖ྡ䛾௦䜟䜚䛻䚸䝩䝇䝖ྡ䛛IP䜰䝗䝺䝇ཬ䜃䝫䞊䝖␒ྕ䜢ᣦᐃ䛧䜎䛩䚹■ docker push example.com:5000/repository○ Ⓩ㘓䛧䛯䝸䝫䝆䝖䝸䛿䚸docker pull䝁䝬䞁䝗䛷䝎䜴䞁䝻䞊䝗䛧䛶฼⏝ฟ᮶䜎䛩䚹
  • 30. 䝺䝆䝇䝖䝸● docker search○ 䝺䝆䝇䝖䝸䛻Ⓩ㘓䛥䜜䛶䛔䜛䝸䝫䝆䝖䝸䜢᳨⣴䛧䜎䛩䚹○ ᶆ‽䛷䛿බᘧ䝺䝆䝇䝖䝸䛂Docker HUB䛃䛾䝸䝫䝆䝖䝸䜢᳨⣴⾲♧䛧䜎䛩䚹○ docker search centos○ OFFICIAL䛜බᘧ䝸䝫䝆䝖䝸○ AUTOMATED䛿⮬ື䝡䝹䝗䛾䝸䝫䝆䝖䝸
  • 31. 䝺䝆䝇䝖䝸● Automated Build○ Dockerfile䛛䜙Docker Hubୖ䛷䝸䝫䝆䝖䝸䜢web⏬㠃᧯స䛷⮬ືసᡂ䛧䜎䛩䚹○ GitHub䜎䛯䛿Bitbucket䛾䜰䜹䜴䞁䝖䛜ᚲせ䚹○ Dockerfile䜢GitHub䜎䛯䛿Bitbucket䛻Ⓩ㘓䚹○ Docker Hub䛾㐃ᦠᶵ⬟䛷䚸䝁䞁䝔䝘䛾⏕ᡂ䛛䜙䜲䝯䞊䝆సᡂ䛸Ⓩ㘓䜢⮬ືⓗ䛻ฟ᮶䜛䚹○ 䝖䝸䜺䞊タᐃ䛷䚸Dockerfile䛾ኚ᭦䛻ྜ䜟䛫䛶⮬ື䝡䝹䝗䛜ฟ᮶䜛䚹
  • Comments
    Top