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
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
610
モバイルアプリにおける自動テストの導入戦略
ostk0069
0
110
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
530
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
600
fs2-io を試してたらバグを見つけて直した話
chencmd
0
220
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
300
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
130
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
450
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
330
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
14 Years of iOS: Lessons and Key Points
seyfoyun
1
770
良いユニットテストを書こう
mototakatsu
4
1.5k
Featured
See All Featured
Documentation Writing (for coders)
carmenintech
66
4.5k
Automating Front-end Workflow
addyosmani
1366
200k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Facilitating Awesome Meetings
lara
50
6.1k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
5
440
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.4k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Become a Pro
speakerdeck
PRO
26
5k
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