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
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
Content Security Policy入門 セキュリティ設定と 違反レポートのはじめ方 / Introduction to Content Security Policy Getting Started with Security Configuration and Violation Reporting
uskey512
1
520
Ethereum_.pdf
nekomatu
0
460
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
macOS でできる リアルタイム動画像処理
biacco42
9
2.4k
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.4k
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
580
受け取る人から提供する人になるということ
little_rubyist
0
230
as(型アサーション)を書く前にできること
marokanatani
9
2.6k
Featured
See All Featured
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
47
2.1k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
What's in a price? How to price your products and services
michaelherold
243
12k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Faster Mobile Websites
deanohume
305
30k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Building Applications with DynamoDB
mza
90
6.1k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Making Projects Easy
brettharned
115
5.9k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
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