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の上でRailsアプリを動かす ハンズオン
Search
Yuichiro MASUI
April 13, 2016
Programming
4
5.4k
[トレタ社内勉強会 "Dockerの上でRailsアプリを動かす ハンズオン
Yuichiro MASUI
April 13, 2016
Tweet
Share
More Decks by Yuichiro MASUI
See All by Yuichiro MASUI
Vue/Nuxt tutorial for Sendai
masuidrive
0
120
ハッカソンで 作ったアプリを売却した話
masuidrive
0
620
DJ hands on for IT Engineers
masuidrive
1
140
自分の棚卸をして レジュメを書こう
masuidrive
5
1.9k
0から1ヶ月で DJになるまで
masuidrive
4
1.5k
Google Apps Scriptでbotを作る話
masuidrive
1
1.7k
Rails loves React
masuidrive
1
420
トレタの存在理由
masuidrive
0
180
18年でRubyから学んだこと - 関西Ruby会議 2017
masuidrive
3
2.2k
Other Decks in Programming
See All in Programming
僕がつくった48個のWebサービス達
yusukebe
18
17k
ECSのサービス間通信 4つの方法を比較する 〜Canary,Blue/Greenも添えて〜
tkikuc
11
2.3k
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
420
Android 15 でアクションバー表示時にステータスバーが白くなってしまう問題
tonionagauzzi
0
130
GCCのプラグインを作る / I Made a GCC Plugin
shouth
1
150
約9000個の自動テストの 時間を50分->10分に短縮 Flakyテストを1%以下に抑えた話
hatsu38
23
10k
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
23k
破壊せよ!データ破壊駆動で考えるドメインモデリング / data-destroy-driven
minodriven
16
4k
飲食業界向けマルチプロダクトを実現させる開発体制とリアルな現状
hiroya0601
1
390
Vue SFCのtemplateでTypeScriptの型を活用しよう
tsukkee
3
1.5k
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
0
150
Server Driven Compose With Firebase
skydoves
0
390
Featured
See All Featured
What's new in Ruby 2.0
geeforr
342
31k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Embracing the Ebb and Flow
colly
84
4.4k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Designing for humans not robots
tammielis
249
25k
Designing the Hi-DPI Web
ddemaree
280
34k
Optimizing for Happiness
mojombo
376
69k
Building Better People: How to give real-time feedback that sticks.
wjessup
363
19k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Typedesign – Prime Four
hannesfritz
39
2.4k
Designing Experiences People Love
moore
138
23k
Practical Orchestrator
shlominoach
186
10k
Transcript
Docker hands-on in Toreta Yuichiro MASUI
[email protected]
Dockerͱ • ԾԽٕज़ͷΈ߹Θͤ • ܰྔ • ΠϝʔδͷΈ͕͍ͬͯΔ • ͍ࣺͯͷΠϯελϯεͱͷ૬ੑ͕ྑ͍
ϑΝΠϧͱϓϩηε Host OS ϓϩηε ϓϩηε ϓϩηε FS ϓϩηε FS ϑΝΠϧγεςϜ
Docker daemon Container Container Network Network
Docker Container • ϓϩηεͷִ • Dockerϓϩηε͔Βଞͷϓϩηεݟ͑ͳ͍ • ϑΝΠϧγεςϜͷִ • ϓϩηεຖʹݟ͑ΔϑΝΠϧҧ͏
ϑΝΠϧͱϓϩηε
Docker Machine Host OS ϓϩηε ϓϩηε ϑΝΠϧγεςϜ Docker daemon VirtualBox
OSX / Windows Docker Machine ϓϩηε FS ϓϩηε FS Network Network
DockerͰγΣϧىಈ • “Docker Quickstart Terminal”Λ3ຕىಈ • docker run -it ubuntu:14.04
/bin/bash • ps aux • touch /abc123 • docker run -it ubuntu:14.04 /bin/bash • ls / • docker ps
ͳʹ͕ى͍ͬͯ͜Δ͔ • docker run -it ubuntu:14.04 /bin/bash • “ubuntu:14.04” ࣮ߦ͢ΔϑΝΠϧΠϝʔδ
• ϩʔΧϧʹͳ͍߹μϯϩʔυ • ΠϝʔδΛల։͠DockerͰىಈ • “-it” ίϯιʔϧΛܨ͛Δ
ͳʹ͕ى͍ͬͯ͜Δ͔ • ىಈ͢ΔͨΊʹ৽͍͠ϑΝΠϧγεςϜΛ࡞Δ • docker ps -a • docker rm
CONTAINER_ID
Πϝʔδ • ΠϝʔδϑΝΠϧDocker HubͰ • ͢ΔΈΛDocker RegistryͱݺͿ • ֤छΠϝʔδ͕ެࣜʹ͞Ε͍ͯΔ •
https://hub.docker.com/_/ubuntu/
Πϝʔδ • OSҎ֎ʹΞϓϦͷΠϝʔδఏڙ͞Ε͍ͯΔ • docker run -it --rm ruby:2.3.0 /bin/bash
• ruby -v • “--rm" ίϯςφΛऴྃ࣌ʹϑΝΠϧΛফ͢
ࣗͷΠϝʔδΛ࡞Δ • ΠϝʔδʹมߋΛՃ͑Δ • Dockerfile FROM ubuntu:14.04 RUN apt-get update
RUN apt-get install -y apache2 CMD ["/usr/sbin/apache2ctl","-D","FOREGROUND"]
DockfileΛىಈ • docker build -t myapache ./ • “-t myapache”
Πϝʔδ໊ • “./“ DockerfileͷσΟϨΫτϦ • docker run -p 8080:80 myapache • http://192.168.99.100:8080 • docker-machine ip
docker-machine • docker-machine restart • $(docker-machine env)
ڧ੍ఀࢭ • docker ps • docker stop CONTAINER_ID
ϗετͷϑΝΠϧΛϚϯτ • docker run -v `pwd`:/var/www/html -p 8080:80 myapache
Containerؒ௨৴ • Containerಠཱ͍ͯ͠ΔͷͰlocalhostͰΞΫ ηεͰ͖ͳ͍ • ͦͷลΛ؆୯ʹ͢Δͷ͕Docker Compose
docker-compose.yml rails: build: . command: [“./bin/rails","server","-b","0.0.0.0"] mem_limit: 512m ports: -
"3000:3000" volumes: - ".:/usr/src/app" links: - "mysql" mysql: image: mysql:5.6 environment: MYSQL_ROOT_PASSWORD: "passwd"
ΊΜͲ͍ͷͰϫϯϥΠφʔ • DockerͰRails։ൃڥΛ࡞ΔϫϯϥΠφʔ • http://qiita.com/masuidrive/items/7478fb9101652f2bbae1
docker-compose ࣮ߦ • docker-compose build • docker-compose up • docker-compose
rm
database.yml • default: &default adapter: mysql2 username: root password: "passwd"
host: mysql • production: <<: *default host: <%= ENV[‘MYSQL_HOST'] %> ↑͜ͷߦΛՃ
scaffold • docker-compose up -d • docker-compose run rails /bin/bash
• rails g scaffold item key:string value:text • rake db:create db:migrate • http://192.168.99.100:3000/items • docker-compose stop
Amazon ECS & ECR • Amazon EC2 Container System •
Dockerͱecs-agentೖΓઐ༻ͷAMI • DockerΛૢ࡞͢Δίϯιʔϧ & API • Amazon EC2 Container Registry • Docker Registry
ECRʹRepositoryΛ࡞ • ը໘ӈ্ͷRegionN.Virginia • Sample appͷνΣοΫΛ֎ͯ͠ • “sample1”ͷϦϙδτϦΛ࡞Δ
ECRʹimageΛpush • $(aws ecr get-login --region us-east-1) • docker build
-t sample1 . • docker tag sample1:latest 123456.dkr.ecr.us- east-1.amazonaws.com/sample1:latest • docker push 123456.dkr.ecr.us- east-1.amazonaws.com/sample1:latest
RDS࡞Ζ͏ • ύεϫʔυ͖ͳϞϊΛ • Publicly access”NO”Ͱ
ECS Cluster
ECS instance • cluster࡞ͬͯ • ecs AMIͰΠϯελϯε࡞ΔɻIAM roleΕͣʹ • http://docs.aws.amazon.com/AmazonECS/latest/
developerguide/instance_IAM_role.html
None
None
None
None
None
Task defnition • docker-composeʹ૬ • ίϯςφͷͨΊͷڥΛઃఆ
None
None
None
ಉ͡Α͏ʹmigrate Task • appͱ΄΅ಉ͡ • Portઃఆ͠ͳ͍ • Commandɺ./bin/rake,db:migrate
Service
Service ͱ Task • Service͕TaskΛ্ཱͪ͛Δ • Task1ͭҎ্ͷContainerΛ༗͢Δ • Task͕མͪΔͱService͕ࣗಈతʹTaskΛىಈ •
Service͔Βىಈ͞Εͳ͍λεΫ୯ൃىಈ • rake db:migrateͱ͔
production.logΛݟΔ • sshͯ͠ • docker ps • docker exec -it
CONTAINER_ID /bin/bash