Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
すぐできるDocker
Search
hidekuni KAJITA
January 25, 2018
Programming
1.4k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
すぐできるDocker
2018 アジャイル事業部 年始のご挨拶
hidekuni KAJITA
January 25, 2018
Transcript
26 slides
すぐできる 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便利!! 簡単に使い始められるのでドンド ン使っていきましょう!
More Decks by hidekuni KAJITA
See All by hidekuni KAJITA
あれのその後.pdf
hidenba
0
47
NVIDIABroadcast便利
hidenba
0
160
レバーレスアケコンを作った話
hidenba
0
94
「冒険できる社会」を実現する “あしたのチーム”
hidenba
0
190
DataChannel を利用した ホワイトボードアプリ開発事例
hidenba
0
1.1k
リズムから生まれるアジャイルな開発
hidenba
0
630
Other Decks in Programming
See All in Programming
joyful-journey-spring-boot.pdf
hollycummins
0
130
AI駆動TDD ― 2026年10月版
hrmstrsmgs
0
120
高橋メソッドでCVE解説シリーズ 〜CVE-2026-112816〜
hakkadaikon
0
280
AWS CDKを理解するために公式の定義を深掘って解説してみる / Understanding AWS CDK by Digging into Its Official Definition
akihisaikeda
3
360
Enforcing Your Architecture with Unit Tests in the AI Era (Swift Connection X)
steliosf
PRO
1
200
SODA - FACT BOOK(JP)
sodainc
1
40k
Getting Started with Vibe Coding
miccheng
0
250
止まらない比較を止める — 余帰納法で無限ストリームを比べる
tarao
0
220
SODA - FACT BOOK(EN)
sodainc
1
310
テスト駆動開発から学ぶ 達人プログラマーの型 / TechRAMEN 2026 Conference
a_okui
0
3.2k
Growing PicoRuby's Ecosystem on ESP32
yuuu
2
150
作れるエンジニアから、価値を届けるエンジニアへ
ryunakayama
1
1.3k
Featured
See All Featured
How to Ace a Technical Interview
jacobian
280
24k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
480
Tell your own story through comics
letsgokoyo
1
1.1k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1.1k
The agentic SEO stack - context over prompts
schlessera
0
1k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.9k
Prompt Engineering for Job Search
mfonobong
0
610
AI Search: Where Are We & What Can We Do About It?
aleyda
0
8.3k
Build your cross-platform service in a week with App Engine
jlugia
234
19k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Navigating Team Friction
lara
192
16k