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
受け取る人から提供する人になるということ
little_rubyist
0
250
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
480
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
CSC509 Lecture 11
javiergs
PRO
0
180
subpath importsで始めるモック生活
10tera
0
310
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
340
as(型アサーション)を書く前にできること
marokanatani
10
2.7k
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.2k
Better Code Design in PHP
afilina
PRO
0
130
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
3
690
CSC509 Lecture 09
javiergs
PRO
0
140
Click-free releases & the making of a CLI app
oheyadam
2
120
Featured
See All Featured
Visualization
eitanlees
145
15k
Producing Creativity
orderedlist
PRO
341
39k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
[RailsConf 2023] Rails as a piece of cake
palkan
52
4.9k
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
How GitHub (no longer) Works
holman
310
140k
Fireside Chat
paigeccino
34
3k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
430
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Ruby is Unlike a Banana
tanoku
97
11k
Writing Fast Ruby
sferik
627
61k
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