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

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

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

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

Mitsuki Ogasahara

October 21, 2016
Tweet

More Decks by Mitsuki Ogasahara

Other Decks in Technology

Transcript

  1. @yamitzky
    %PDLFSpMFΛ
    ૉૣ͘࡞Δ

    UJQTˍϥΠϒσϞ
    2016/10/21 JXࣾ಺ษڧձ

    View full-size slide

  2. w ࣗ෼͕%PDLFSpMFΛॻ͘ͱ͖ʹɺ

    Ͳ͏͍͏؀ڥͰॻ͍͍ͯΔ͔Λڞ༗ˍσϞ͠·͢
    w ʮ͜͏͢Δͱ΋ͬͱޮ཰ྑ͍ΑʂʯͳͲ͋ͬͨΒ

    ϚαΧϦ͓ئ͍͠·͢
    Today…

    View full-size slide

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

    ଞͷ؀ڥͰ΋࢖͑ΔΑ͏ʹڞ༗Ͱ͖Δ
    What is Docker?
    %PDLFSpMFΛॻ͍ͯɺ
    ΞϓϦέʔγϣϯΛ୭Ͱ΋࢖͑ΔΑ͏ʹ͠Α͏ʂ

    View full-size slide

  4. w ࠷ۙࣗ෼͕ॻ͍ͨ%PDLFSpMF
    w EPDLFSDPNQPTF
    w BQFY
    w NFDBC
    w +6."/
    w FUDʜ
    Recently…
    %PDLFSΠϝʔδΛڞ༗͢Ε͹

    AEPDLFSSVOA͚ͩͰ.BDͰ΋8JOEPXTͰ΋-JOVYͰ΋
    ར༻Ͱ͖ΔΑ͏ʹʂ

    View full-size slide

  5. Bad Practice to Write Dockerfile
    $
    5FSNJOBM

    View full-size slide

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

    View full-size slide

  7. 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

    View full-size slide

  8. Bad Practice to Write Dockerfile
    $ docker build .
    #VJME%PDLFSJNBHFBOEXBJUʜ
    ...
    (wait for 10 min)

    View full-size slide

  9. 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

    View full-size slide

  10. Bad Iteration
    $ build

    8SJUF #VJME8BJU &SSPS

    View full-size slide

  11. #FTU1SBDUJDF

    View full-size slide

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

    View full-size slide

  13. Best Practice to Write Dockerfile
    $
    3VOUNVYTQMJUQBOF
    $

    View full-size slide

  14. Best Practice to Write Dockerfile
    $ vim Dockerfile $ docker run -it
    alpine /bin/sh
    &EJU%PDLFSpMF 3VOCBTFJNBHF`TTIFMM

    View full-size slide

  15. Best Practice to Write Dockerfile
    / #
    8SJUFKVTUPOFMJOF
    FROM alpine
    RUN apk add —no-cache curl
    4IFMMJTSVOOJOH

    View full-size slide

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

    View full-size slide

  17. w ʮWJNTMJNFʯͱ͔ʮFNBDTTMJNFʯͰݕࡧʂ
    w ΤσΟλʔͷબ୒෦෼ΛɺUNVYͷผQBOFʹૹΓɺ

    ࣮ߦͰ͖ΔϓϥάΠϯ

    Slime?
    IUUQTHJUIVCDPNKQBMBSEZWJNTMJNF

    View full-size slide

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

    View full-size slide

  19. / # some command
    Best Practice to Write Dockerfile
    / # apk add —no-cache curl

    &YFDVUFPOFMJOFWJB4-*.&
    FROM alpine
    RUN apk add —no-cache curl
    RUN some command

    View full-size slide

  20. / # 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

    View full-size slide

  21. Finally…
    $ docker build .
    4BWFCVJMEJU
    $
    ...
    ...
    Successfully built

    View full-size slide

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

    ྫɿFNBDTTMJNFͱ͔JOUFMMJ+ͱ͔

    Conclusion

    View full-size slide