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
130
ハッカソンで 作ったアプリを売却した話
masuidrive
0
630
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
430
トレタの存在理由
masuidrive
0
180
18年でRubyから学んだこと - 関西Ruby会議 2017
masuidrive
3
2.2k
Other Decks in Programming
See All in Programming
Effective Signals in Angular 19+: Rules and Helpers @ngbe2024
manfredsteyer
PRO
0
140
Webエンジニア主体のモバイルチームの 生産性を高く保つためにやったこと
igreenwood
0
340
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
460
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
120
今年一番支援させていただいたのは認証系サービスでした
satoshi256kbyte
1
260
nekko cloudにおけるProxmox VE利用事例
irumaru
3
430
創造的活動から切り拓く新たなキャリア 好きから始めてみる夜勤オペレーターからSREへの転身
yjszk
1
130
数十万行のプロジェクトを Scala 2から3に完全移行した
xuwei_k
0
270
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
250
StarlingMonkeyを触ってみた話 - 2024冬
syumai
3
270
create_tableをしただけなのに〜囚われのuuid編〜
daisukeshinoku
0
260
Monixと常駐プログラムの勘どころ / Scalaわいわい勉強会 #4
stoneream
0
280
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
137
6.7k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.4k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
520
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Navigating Team Friction
lara
183
15k
Designing for Performance
lara
604
68k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
How to Think Like a Performance Engineer
csswizardry
22
1.2k
Designing for humans not robots
tammielis
250
25k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
29
2k
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