Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥

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

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

Takumi Shotoku

December 02, 2021
Tweet

More Decks by Takumi Shotoku

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ • ໊લ: ਖ਼ಙ ޼(aka: ਆ଎) • ձࣾ: ϝυϐΞגࣜձࣾ •

    ॴଐ: CTOࣨSRE • GitHub: @sinsoku (ը૾ӈ্) • Twitter: @sinsoku_listy (ը૾ӈԼ) 2
  2. ࠷ߴͷϒϩάΞϓϦΛ࡞Δ (3min) $ rails new omotesando_blog $ cd omotesando_blog $

    bin/rails g scaffold blog title body:text $ bin/rails db:prepare $ bin/rails s 3
  3. ΞϓϦͷίϯςφԽ omotesando_blog ͱ͍͏όΠφϦΛ࡞Δͷʹ͍ۙɻ $ docker run omotesando_blog bin/rails --version $

    docker run omotesando_blog bin/rails stats omotesando_blog ͷDockerΠϝʔδʹ͸ιʔείʔυɺRubyɺ gemɺnpmؚ͕·Ε͍ͯΔͷͰɺར༻ऀ͸Docker͚ͩ༻ҙ͢Ε͹ ྑ͍ɻ 7
  4. 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
  5. Ϗϧυͯ͠ࢼ͢ $ docker build -t omotesando_blog . $ docker run

    -p 3000:3000 \ omotesando_blog bin/rails s -b 0.0.0.0 9
  6. 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
  7. 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
  8. Ϗϧυͯ͠ࢼ͢ $ 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