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

Dockerfileを素早く書くtips&ライブデモ

 Dockerfileを素早く書くtips&ライブデモ

2016/10/21 JX通信社の社内勉強会で話した内容です

90dbd6fb1763a4b5f7236b72cba16a58?s=128

Mitsuki Ogasahara

October 21, 2016
Tweet

Transcript

  1. @yamitzky %PDLFSpMFΛ ૉૣ͘࡞Δ
 UJQTˍϥΠϒσϞ 2016/10/21 JXࣾ಺ษڧձ

  2. w ࣗ෼͕%PDLFSpMFΛॻ͘ͱ͖ʹɺ
 Ͳ͏͍͏؀ڥͰॻ͍͍ͯΔ͔Λڞ༗ˍσϞ͠·͢ w ʮ͜͏͢Δͱ΋ͬͱޮ཰ྑ͍ΑʂʯͳͲ͋ͬͨΒ
 ϚαΧϦ͓ئ͍͠·͢ Today…

  3. w ίϯςφܕͷԾ૝Խ؀ڥΛఏڙ͢Δ044 w %PDLFSpMFʹΑͬͯ%PDLFSΠϝʔδΛఆٛͰ͖Δ w Ϗϧυͨ͠%PDLFSΠϝʔδ͸%PDLFS3FHJTUSZͰެ։Ͱ͖ɺ
 ଞͷ؀ڥͰ΋࢖͑ΔΑ͏ʹڞ༗Ͱ͖Δ What is Docker?

    %PDLFSpMFΛॻ͍ͯɺ ΞϓϦέʔγϣϯΛ୭Ͱ΋࢖͑ΔΑ͏ʹ͠Α͏ʂ
  4. w ࠷ۙࣗ෼͕ॻ͍ͨ%PDLFSpMF w EPDLFSDPNQPTF w BQFY w NFDBC w +6."/

     w FUDʜ Recently… %PDLFSΠϝʔδΛڞ༗͢Ε͹
 AEPDLFSSVOA͚ͩͰ.BDͰ΋8JOEPXTͰ΋-JOVYͰ΋ ར༻Ͱ͖ΔΑ͏ʹʂ
  5. #BE1SBDUJDF

  6. Bad Practice to Write Dockerfile $ 5FSNJOBM

  7. Bad Practice to Write Dockerfile $ vim Dockerfile 0QFOFEJUPS

  8. Bad Practice to Write Dockerfile FROM alpine RUN apk add

    —no-cache curl RUN command to take long time RUN some typo command 8SJUF%PDLFSpMF
  9. Bad Practice to Write Dockerfile $ docker build . #VJME%PDLFSJNBHFBOEXBJUʜ

    ... (wait for 10 min)
  10. Bad Practice to Write Dockerfile $ docker build . &SSPS

    ... ... /bin/sh: typo: not found The command '/bin/sh -c typo' returned a non-zero code: 127
  11. None
  12. Bad Iteration $ build ☕ 8SJUF #VJME8BJU &SSPS

  13. #FTU1SBDUJDF

  14. Best Practice to Write Dockerfile 5NVYɺ7JNɺ4MJNFΛ࢖ͬͯ Ұߦͣͭ%PDLFSpMFΛ͔֬ΊΔ Ҏ্ɻ

  15. %&.0

  16. Best Practice to Write Dockerfile $ 3VOUNVYTQMJUQBOF $

  17. Best Practice to Write Dockerfile $ vim Dockerfile $ docker

    run -it alpine /bin/sh &EJU%PDLFSpMF 3VOCBTFJNBHF`TTIFMM
  18. Best Practice to Write Dockerfile / # 8SJUFKVTUPOFMJOF FROM alpine

    RUN apk add —no-cache curl 4IFMMJTSVOOJOH
  19. Best Practice to Write Dockerfile / # apk add —no-cache

    curl &YFDVUFPOFMJOFWJB4-*.& FROM alpine RUN apk add —no-cache curl
  20. w ʮWJNTMJNFʯͱ͔ʮFNBDTTMJNFʯͰݕࡧʂ w ΤσΟλʔͷબ୒෦෼ΛɺUNVYͷผQBOFʹૹΓɺ
 ࣮ߦͰ͖ΔϓϥάΠϯ
 Slime? IUUQTHJUIVCDPNKQBMBSEZWJNTMJNF

  21. Best Practice to Write Dockerfile / # apk add —no-cache

    curl &YFDVUFPOFMJOFWJB4-*.& FROM alpine RUN apk add —no-cache curl
  22. / # some command Best Practice to Write Dockerfile /

    # apk add —no-cache curl … &YFDVUFPOFMJOFWJB4-*.& FROM alpine RUN apk add —no-cache curl RUN some command
  23. / # some command … Best Practice to Write Dockerfile

    / # apk add —no-cache curl … &YFDVUFPOFMJOFWJB4-*.& FROM alpine RUN apk add —no-cache curl RUN some command RUN other command / # other command
  24. Finally… $ docker build . 4BWFCVJMEJU $ ... ... Successfully

    built
  25. w UNVYͱWJNͱTMJNFΛ༻ҙ͢Δ w ҰߦͣͭTMJNFͰ࣮ߦ͔ͯ͠Βɺ࠷ޙʹAEPDLFSCVJMEA w λʔϛφϧʹ̍ߦͣͭίʔυΛૹΕΕ͹ԿͰ΋ྑ͍Αʂ
 ྫɿFNBDTTMJNFͱ͔JOUFMMJ+ͱ͔ Conclusion