Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
すぐできるDocker
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
hidekuni KAJITA
January 25, 2018
Programming
1.3k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
すぐできるDocker
2018 アジャイル事業部 年始のご挨拶
hidekuni KAJITA
January 25, 2018
More Decks by hidekuni KAJITA
See All by hidekuni KAJITA
あれのその後.pdf
hidenba
0
36
NVIDIABroadcast便利
hidenba
0
150
レバーレスアケコンを作った話
hidenba
0
85
「冒険できる社会」を実現する “あしたのチーム”
hidenba
0
170
DataChannel を利用した ホワイトボードアプリ開発事例
hidenba
0
1k
リズムから生まれるアジャイルな開発
hidenba
0
620
Other Decks in Programming
See All in Programming
AI時代のPHPer生存戦略 ~「言語、もうなんでもよくない?」に本気で向き合う~
vivion
0
360
数百円から始めるRuby電子工作
tarosay
0
150
生成AIで帳票OCRが「簡単に」作れる時代になった?
kon_shou
0
840
自動化したのに回らないテスト運用の壁ーAI時代の品質責任と生産性
mfunaki
0
130
ルールを書いて終わらせないハーネスエンジニアリング
yug1224
4
1.9k
Lean は証明の正しさを確認するためだけのツールって思ってませんか?
inoueasei
1
160
Go言語とトイモデルで学ぶTransformerの気持ち / fukuokago23-transformer
monochromegane
0
170
「寝てても仕事が進む」Claude Codeで組む第二の脳
tomoyafujita2016
0
330
Go 1.27 における memory allocation の高速化
andpad
0
170
Japan Community Day at Kubecon + CloudNativeCon Japan 2026: Learning Container Privilege Control by Building My Own Low-Level Container Runtime
ternbusty
1
150
Foundation Models frameworkで画像分析
ryodeveloper
1
610
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
470
Featured
See All Featured
Java REST API Framework Comparison - PWX 2021
mraible
34
9.6k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.3k
Facilitating Awesome Meetings
lara
57
7.1k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
340
How GitHub (no longer) Works
holman
316
150k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Faster Mobile Websites
deanohume
310
32k
GraphQLとの向き合い方2022年版
quramy
50
15k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.5k
How STYLIGHT went responsive
nonsquared
100
6.2k
Transcript
すぐできる Docker かじたひでくに 2018/01/24
自己紹介 梶田英邦(かじたひでくに) @hide_nba Ruby/Railsを使ってお仕事して ます 2018年7月を担当
やってみよう! YARIMASU!!
Dockerfileの作成 FROM ruby:2.5 RUN groupadd --gid 1000 developer \ &&
useradd --uid 1000 --gid developer --shell /bin/bash --create-home developer RUN apt-get update && apt-get install -y nodejs ENV APP_HOME /usr/src/app RUN mkdir -p $APP_HOME WORKDIR $APP_HOME COPY Gemfile \ Gemfile.lock \ $APP_HOME/ ENV BUNDLE_GEMFILE=$APP_HOME/Gemfile \ BUNDLE_JOBS=4
docker-compose.ymlの 作成 version: '3' services: db: image: mysql ports: -
"3306:3306" volumes: - mysql_data:/var/lib/mysql app: build: . user: 1000:1000 command: bin/rails s -p 3000 -b "0.0.0.0" depends_on: - db ports: - "3000:3000" stdin_open: true tty: true volumes: - .:/usr/src/app - bundle_cache:/usr/local/bundle volumes: bundle_cache: mysql_data:
Gemfileの作成 # frozen_string_literal: true source "https://rubygems.org" git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem "rails"
Gemfile.lockの作成 $ touch Gemfile.lock
bundle install $ docker-compose run app bundle install
rails new $ docker-compose run app rails new . --force
--database mysql
config/database.ymlの 編集 diff --git a/config/database.yml b/config/database.yml index 6003576..2213f5b 100644 ---
a/config/database.yml +++ b/config/database.yml @@ -14,8 +14,7 @@ default: &default encoding: utf8 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> username: root - password: - host: localhost + host: db development: <<: *default
サーバ起動 $ docker-compose up
動いた!
Dockerfile FROM ruby:2.5 RUN groupadd --gid 1000 developer \ &&
useradd --uid 1000 --gid developer --shell /bin/bash --create-home developer RUN apt-get update && apt-get install -y nodejs ENV APP_HOME /usr/src/app RUN mkdir -p $APP_HOME WORKDIR $APP_HOME COPY Gemfile \ Gemfile.lock \ $APP_HOME/ ENV BUNDLE_GEMFILE=$APP_HOME/Gemfile \ BUNDLE_JOBS=4
FROM FROM ruby:2.5 Rubyのバージョン2.5が入ってい るイメージを利用する
groupadd && useradd RUN groupadd --gid 1000 developer \ &&
useradd --uid 1000 --gid developer --shell /bin/bash --create-home developer イメージ内にグループID(1000)と ユーザID(1000)のグループとユー ザを作成
WORKDIR ENV APP_HOME /usr/src/app RUN mkdir -p $APP_HOME WORKDIR $APP_HOME
イメージ内に /usr/src/app を 作成してコンテナ実行時の作業 ディレクトとする
BUNDLE_XXXX ENV BUNDLE_GEMFILE=$APP_HOME/Gemfile \ BUNDLE_JOBS=4 bundlerの設定
docker-compose.yml version: '3' services: db: image: mysql ports: - "3306:3306"
volumes: - mysql_data:/var/lib/mysql app: build: . user: 1000:1000 command: bin/rails s -p 3000 -b "0.0.0.0" depends_on: - db ports: - "3000:3000" stdin_open: true tty: true volumes: - .:/usr/src/app - bundle_cache:/usr/local/bundle volumes: bundle_cache: mysql_data:
named volume volumes: bundle_cache: mysql_data: この名前でvolumeのマウントを 行える 永続化する場所を気にせずにお 手軽
データベース設定 services: db: image: mysql ports: - "3306:3306" volumes: -
mysql_data:/var/lib/mysql サービス名はコンテナ間の名前解 決にも利用される
services.db image: mysql mysqlのイメージを使用する ports: ホスト側とコンテナ側の使用ポート volumes: mysql_dataをコンテナ側の /var/lib/ mysql
をマウントする
アプリケーション設定 services: app: build: . user: 1000:1000 command: bin/rails s
-p 3000 -b "0.0.0.0" depends_on: - db ports: - "3000:3000" stdin_open: true tty: true volumes: - .:/usr/src/app - bundle_cache:/usr/local/bundle
services.app(1) build . カレントディレクトリのDockerfileをビ ルドする user: 1000:1000 UID/GID 1000 でコマンドを実行する
services.app(2) command: bin/rails s -p 3000 -b “0.0.0.0” コンテナ起動時に実行されるコマンド depends_on:
-db dbコンテナが起動してから起動するよう に設定
services.app(3) volumes: - .:/usr/src/app ホスト側のカレントディレクト リをコンテナ側の/usr/src/app にマウント
まとめ Docker便利!! 簡単に使い始められるのでドンド ン使っていきましょう!