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
More Decks by hidekuni KAJITA
See All by hidekuni KAJITA
あれのその後.pdf
hidenba
0
41
NVIDIABroadcast便利
hidenba
0
150
レバーレスアケコンを作った話
hidenba
0
91
「冒険できる社会」を実現する “あしたのチーム”
hidenba
0
180
DataChannel を利用した ホワイトボードアプリ開発事例
hidenba
0
1.1k
リズムから生まれるアジャイルな開発
hidenba
0
630
Other Decks in Programming
See All in Programming
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
2.9k
標準パッケージに uuid が追加された 背景から見る Go らしい意思決定 / go_127_uuid_decision
convto
5
8.2k
Snowflakeで業務アプリを作ろう。 Snowflakeのアプリ機能解説&実践ガイド
ayumu_yamaguchi
2
300
大喜利で理解するLLM as a Judge / Understanding LLM-as-a-Judge through Ogiri
rockname
0
160
スマートフォンでモールス信号を送受信する 〜スマートフォンのLEDとカメラで作る光通信の設計と実装〜
atsuki_seo
0
170
変化を抱擁するドキュメントの作り方 - ビジネスルール駆動開発がもたらす、コードとの新しい関係
ioki
2
220
Jetpack Compose メカニズム
skydoves
0
460
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
4.9k
速習iPhone Duo対応
yuukiw00w
1
710
アクセシビリティから考える情報設計
high_g_engineer
0
380
Webの地図
yosuke_furukawa
PRO
6
4.7k
Omarchy Tokyo やると聞いて UMPC 買ってセットアップしてきた
mtsmfm
0
160
Featured
See All Featured
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Rails Girls Zürich Keynote
gr2m
96
14k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
250
Side Projects
sachag
456
43k
The SEO identity crisis: Don't let AI make you average
varn
0
560
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
910
Facilitating Awesome Meetings
lara
57
7.1k
Designing for humans not robots
tammielis
254
26k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1k
AI: The stuff that nobody shows you
jnunemaker
PRO
10
1.1k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.6k
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
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便利!! 簡単に使い始められるのでドンド ン使っていきましょう!