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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
1k
リズムから生まれるアジャイルな開発
hidenba
0
620
Other Decks in Programming
See All in Programming
FDEとは、何者なのか?
masapyon1212
0
110
S3 を使うアプリケーションをローカル完結で動かすことに全力を注いでみた / Running S3 Apps Offline
contour_gara
0
730
DroidKaigi 2026 「個人開発という実験場: Android エンジニアが手にする4つの自由」
slashnephy
0
180
in-process GraphQL のすすめ #ginzajs
izumin5210
4
1.5k
初めての模倣学習とVLA
natsutan
0
400
AIを上手に使っていこうとしたら越境せざるを得なくなった話 〜実践1年で見えた境界を越えなければならない理由と進め方〜 / Crossing borders with AI
tomoyakitaura
2
920
自動化したのに回らない テスト運用の壁―AI時代の品質責任と生産性
mfunaki
0
570
Deep dive into the select statement (GopherCon UK)
jespino
0
160
いまどきの Codex で開発する visionOS アプリの開発スタイルについて
karad
0
180
Press start. Python's next generation.
willingc
PRO
3
300
Flow は今どうなっているか
mizdra
PRO
0
820
【デモ】Kiroで体験する仕様駆動開発|設計からコーディングまでAIと進める開発フロー
cmkudo
0
550
Featured
See All Featured
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.6k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
450
Claude Code のすすめ
schroneko
67
230k
How to Talk to Developers About Accessibility
jct
2
530
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
590
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
The Limits of Empathy - UXLibs8
cassininazir
1
630
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
57k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
430
WENDY [Excerpt]
tessaabrams
12
39k
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便利!! 簡単に使い始められるのでドンド ン使っていきましょう!