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

Railsエンジニア向けDocker入門 / Docker description for Rails engineers

Railsエンジニア向けDocker入門 / Docker description for Rails engineers

Takumi Shotoku

December 02, 2021
Tweet

More Decks by Takumi Shotoku

Other Decks in Technology

Transcript

  1. RailsΤϯδχΞ޲͚Dockerೖ໳
    Omotesando.rb #68 2021/12/02
    1

    View full-size slide

  2. ࣗݾ঺հ
    • ໊લ: ਖ਼ಙ ޼(aka: ਆ଎)
    • ձࣾ: ϝυϐΞגࣜձࣾ
    • ॴଐ: CTOࣨSRE
    • GitHub: @sinsoku (ը૾ӈ্)
    • Twitter: @sinsoku_listy (ը૾ӈԼ)
    2

    View full-size slide

  3. ࠷ߴͷϒϩάΞϓϦΛ࡞Δ (3min)
    $ rails new omotesando_blog
    $ cd omotesando_blog
    $ bin/rails g scaffold blog title body:text
    $ bin/rails db:prepare
    $ bin/rails s
    3

    View full-size slide

  4. ϒϩά͕౤ߘͰ͖Δʂ͍͢͝ʂ
    4

    View full-size slide

  5. ଞPCͰ؆୯ʹಈ͘Α͏ʹ͍ͨ͠
    5

    View full-size slide

  6. Dockerͷ༻్ ͦͷ1
    ΞϓϦ ͷίϯςφԽ
    6

    View full-size slide

  7. ΞϓϦͷίϯςφԽ
    omotesando_blog ͱ͍͏όΠφϦΛ࡞Δͷʹ͍ۙɻ
    $ docker run omotesando_blog bin/rails --version
    $ docker run omotesando_blog bin/rails stats
    omotesando_blog ͷDockerΠϝʔδʹ͸ιʔείʔυɺRubyɺ
    gemɺnpmؚ͕·Ε͍ͯΔͷͰɺར༻ऀ͸Docker͚ͩ༻ҙ͢Ε͹
    ྑ͍ɻ
    7

    View full-size slide

  8. Dockerfile ͷྫ1
    FROM ruby:3.0.3
    WORKDIR /workspace
    # Install Node.js, Yarn
    RUN curl -fsSL https://deb.nodesource.com/setup_14.x | bash -
    RUN apt-get update && apt-get install -y nodejs
    RUN npm install --global yarn
    # ιʔείʔυΛ௥Ճ͢Δ
    COPY . /workspace
    # gem΍npmΛ௥Ճ͢Δ
    RUN bin/setup
    8

    View full-size slide

  9. Ϗϧυͯ͠ࢼ͢
    $ docker build -t omotesando_blog .
    $ docker run -p 3000:3000 \
    omotesando_blog bin/rails s -b 0.0.0.0
    9

    View full-size slide

  10. Dockerศར
    10

    View full-size slide

  11. ։ൃ؀ڥ΋
    !
    ʹ͢Ε͹ศར...ʁ
    11

    View full-size slide

  12. Dockerfile ͷྫ1ʢ࠶ܝʣ
    FROM ruby:3.0.3
    WORKDIR /workspace
    # Install Node.js, Yarn
    RUN curl -fsSL https://deb.nodesource.com/setup_14.x | bash -
    RUN apt-get update && apt-get install -y nodejs
    RUN npm install --global yarn
    # ιʔείʔυΛ௥Ճ͢Δ
    COPY . /workspace
    # gem΍npmΛ௥Ճ͢Δ
    RUN bin/setup
    12

    View full-size slide

  13. ίʔυมߋ͢Δ౓ʹϏϧυ͕ඞཁ
    13

    View full-size slide

  14. Dockerͷ༻్ ͦͷ2
    ؀ڥ ͷίϯςφԽ
    14

    View full-size slide

  15. Dockerfile ͷྫ2
    FROM ruby:3.0.3
    WORKDIR /workspace
    # Install Node.js
    RUN curl -fsSL https://deb.nodesource.com/setup_14.x | bash -
    RUN apt-get update && apt-get install -y nodejs
    # Install Yarn
    RUN curl -o- -L https://yarnpkg.com/install.sh | bash
    # Set env to install gems into /workspace/vendor/bundle
    ENV BUNDLE_PATH vendor/bundle
    15

    View full-size slide

  16. Ϗϧυͯ͠ࢼ͢
    $ docker build -t omotesando_blog:v2 .
    $ docker run -v `pwd`:/workspace \
    omotesando_blog:v2 bin/setup
    $ docker run -v `pwd`:/workspace -p 3000:3000 \
    omotesando_blog:v2 bin/rails s -b 0.0.0.0
    omotesando_blog:v2 ʹ͸RubyɺNode.jsɺYarn͸ؚ·Ε͍ͯΔɻ
    ։ൃதʹมߋ͢Δ͜ͱͷ͋Δίʔυɺgemɺnpm͸Πϝʔδʹؚ
    Ίͳ͍ɻ
    16

    View full-size slide

  17. ·ͱΊ
    Dockerͷ༻్͸2ͭ͋Δɻ
    1. ΞϓϦͷίϯςφԽ
    2. ؀ڥͷίϯςφԽ
    ༻్ʹΑͬͯDockerfileͰؾΛ͚ͭΔ఺͕มΘΔͷͰ஫ҙ͕͍Δɻ
    17

    View full-size slide