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 を使ったサービス構築速習会
Search
Daisuke Fujita
April 12, 2016
Technology
2
980
Docker を使ったサービス構築速習会
Docker を使ったサービス構築速習会 @ Wantedly #docker_wantedly の発表資料です
http://wantedly.connpass.com/event/27061/
Daisuke Fujita
April 12, 2016
Tweet
Share
More Decks by Daisuke Fujita
See All by Daisuke Fujita
SREcon19 Asia/Pacific Recap
dtan4
0
150
Our Practices of Delegating Ownership in Microservices World
dtan4
4
8.8k
Kubernetes Cluster Upgrade / Mercari Meetup for Microservices Platform
dtan4
3
4.4k
KubeCon EU 2018 Recap: Multi-Tenancy in Kubernetes: Best Practices Today, and Future Directions / Kubernetes Meetup Tokyo 11 #k8sjp
dtan4
1
1.8k
Wantedly から Chef を一掃した話 / #chibadan
dtan4
24
11k
さようなら Chef こんにちは Dockerfile / Web Tech Tokyo #1
dtan4
6
7k
Docker をフル活用したインフラの紹介と成長し続けるためのインフラ戦略 / #abejameetup
dtan4
19
3.9k
Docker Compose PaaS の作り方、そして社内に導入した話 / #yapc8oji
dtan4
1
8.1k
Writing Kubenetes tools in Go
dtan4
1
3.4k
Other Decks in Technology
See All in Technology
10Xでのデータ基盤の変遷とこれから: データマネジメントのリアル 〜BtoB企業3社の歩みとこれから〜
10xinc
6
1.2k
Understanding and Optimising INP
akshayysharma
0
150
Causal Impactを用いたLINE Pay UIの効果検証とABテスト実施への貢献
lycorptech_jp
PRO
2
460
不感対策ソリューション
jtes
0
230
XP matsuri 2024 - 銀河英雄伝説に学ぶ
kawaguti
PRO
3
470
ORM と向き合う
hoto17296
7
5.9k
仮想化って何だろう
shkoga
0
140
【shownet.conf_】ShowNet x 宇宙ネットワーク
shownet
PRO
0
290
AI時代のアジャイル開発(XP祭り2024版) / Agile Development in the AI Era in XPJUG
takaking22
13
3.4k
VS CodeでF1〜12キーつかってますか? / Do you use the F1-12 keys in VS Code?
74th
1
250
XPを始める新人に伝えたい近道の鍵
nakasho
1
220
【shownet.conf_】コンピューティング資源を統合した分散コンテナ基盤の進化
shownet
PRO
0
290
Featured
See All Featured
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
327
21k
Typedesign – Prime Four
hannesfritz
39
2.3k
How GitHub (no longer) Works
holman
310
140k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
23
1.7k
Building Applications with DynamoDB
mza
90
6k
Unsuck your backbone
ammeep
667
57k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
279
13k
Fashionably flexible responsive web design (full day workshop)
malarkey
403
65k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
663
120k
GitHub's CSS Performance
jonrohan
1030
450k
Fontdeck: Realign not Redesign
paulrobertlloyd
81
5.2k
Transcript
%PDLFSΛͬͨ αʔϏεߏங शձ!8"/5&%-: EPDLFS@XBOUFEMZ %BJTVLF'VKJUB!EUBO ʢެ։൛ʣ
Daisuke Fujita @dtan4 Πϯλʔϯ @ΠϯϑϥνʔϜ
࣭4ZODͷ෦ʹͯड͚͚·͢ ʢຊΑΓʣ.BD"QQ4UPSF͔ΒμϯϩʔυͰ͖·͢ʂ CHECK! http://s.wantedly.com/1SL5Um0
%PDLFSೖͬͯ·͔͢ʁಈ͖·͔͢ʁ CHECK! $ docker -v Docker version 1.10.0, build 590d510
$ docker ps CONTAINER ID … $ docker-compose -v docker-compose version 1.6.0, build unknown ʢόʔδϣϯಛʹؾʹ͠ͳ͍Ͱ͢ɻͪΖΜ࠷৽Ͱ͋Δ΄ͲΑ͍ʣ
ຊͷ༰ w 8BOUFEMZͰͷ։ൃʹ͓͚Δॾ w %PDLFS$PNQPTFͰαʔϏεΛಈ͔ͦ͏ w %PDLFS$PNQPTFͰߏஙͨ͠ΞϓϦΛ σϓϩΠ͠Α͏ w %PDLFS1BB4*BB4
Wantedly Ͱͷ։ൃʹ ͓͚Δॾ
www.wantedly.com Λ ࢧ͑Δٕज़ w 3BJMTͷ΄͔ʹʜ w 1PTUHSF42- w &MBTUJDTFBSDI w
.FNDBDIFE w 3FEJT w 1IBOUPN+4 w ։ൃɾςετʹ͜ΕΒͷαʔϏε͕ඞཁ
www.wantedly.com Λ ࢧ͑Δٕज़ w )PNFCSFXʹΑΔ։ൃڥߏங w brew updateͰ։ൃڥ͕յΕΔ w &MBTUJDTFBSDIຊମͱϓϥάΠϯͷ
όʔδϣϯΛγϏΞʹ߹Θͤͳ͍ͱμϝ w ຊ൪ͷ&MBTUJDBDIF3FEJTYͷΈ w ΠϯετʔϧεΫϦϓτͰແཧΓ όʔδϣϯΛݻఆʜ w bundle install͕ࣦഊʢಛʹ$֦ுHFNʣ
Elasticsearch on Docker
Elasticsearch on Docker w ຊ൪ͷ&MBTUJDTFBSDI%PDLFSίϯςφͱ ͯ͠Քಇ͍ͯ͠Δ w RVBZJP্ͰΠϝʔδཧ w αʔϏεʹ߹Θͤͨνϡʔχϯά
w ಠࣗࣙॻΛಉࠝ w ͜ΕΛ։ൃςετͰ͍͍ͨʜ
ϑΟʔνϟϒϥϯνͷ σϓϩΠ w ຊ൪ڥ 1SPEVDUJPO 2"ڥ 2" w
2"ॱ൪ͪ w 2"ͭͩͱΓͳ͘ͳ͖ͬͯͨ w ࣗͷϒϥϯνΛؾܰʹσϓϩΠͰ͖Δ ڥ͕΄͍͠
ϚΠΫϩαʔϏεج൫ w ੲ͔Β3BJMTͰ࣮͞Ε͍ͯͨػೳʹ͍ͭͯɺ ύϑΥʔϚϯε্ͷͨΊʹ(PͰ࠶࣮ ͢Δྫ͕͋Δ w 4ZOD8BOUFEMZ5PPMTͷΑ͏ʹɺຊମͱ ҟͳΔαʔϏεΛϦϦʔε͢Δػձ͕ ૿͑ͨ w
͜Μͳͱ͖ɺΛ͔͚ͯΠϯϑϥΛ༻ҙ͢ ΔͷͰͳ͘DockerfileΛॻ͚σϓϩΠͰ ͖ΔΑ͏ͳڥ͕΄͍͠
Docker
Docker Ͱڥߏங w ΞϓϦ୯ҐͰڥΛಠཱͤ͞ΒΕΔ w ͜ͷαʔϏεͰ&Tɺ͋ͷαʔϏεͰ &TʜͰॊೈʹରԠՄೳ w ຊ൪ڥΛखݩͰ༰қʹ࠶ݱՄೳ w
ΞʔΩςΫνϟґଘ͔Β٫Ͱ͖Δ w ඇΠϯϑϥͰ%PDLFSpMFΛॻ͖͍͢ w ͳͲͳͲ
Docker Ͱڥߏங w ෳίϯςφͷཧ͕໘ w 3BJMT൪ϙʔτͰཱͨͤͯɺ 1PTUHSF42-ͱMJOLͰͭͳ͛ͯʜ w ্ཱͪ͛ॱংߟྀ͠ͳ͍ͱ͍͚ͳ͍ 1PTUHSF42-
3FEJT 3BJMT 3000/tcp link db:postgres link redis:redis
Docker Compose
EPDLFSDPNQPTF Docker Compose w ෳͷ%PDLFSίϯςφͰߏ͞ΕΔΞϓϦ Λ؆୯ʹཧ͢ΔͨΊͷπʔϧ w :".-Ͱ֤ίϯςφͷىಈߏͱ࿈ܞΛهड़ w docker
runͷΦϓγϣϯΛߏతʹ ॻ͚ΔͨΊɺ୯ҰίϯςφͰศར w ίϚϯυҰൃͰΞϓϦͷVQEPXO TDBMJOH͕Մೳ
docker-compose.yml ຊൃදͰ$PNQPTFpMFGPSNBUWʹ ४ڌͯ͠આ໌͍͖ͯ͠·͢ db: image: postgres web: build: . command:
bundle exec rails s -p 3000 -b '0.0.0.0' volumes: - .:/myapp ports: - "3000:3000" links: - db
docker-compose.yml ຊൃදͰ$PNQPTFpMFGPSNBUWʹ ४ڌͯ͠આ໌͍͖ͯ͠·͢ db: image: postgres web: build: . command:
bundle exec rails s -p 3000 -b '0.0.0.0' volumes: - .:/myapp ports: - "3000:3000" links: - db $ docker build . web $ docker run -p 3000:3000 -v .:/myapp --links db web
$ git clone \ https://github.com/dtan4/docker-service-rails.git $ git checkout step0 Docker
Compose Ͱ Rails ΛݐͯͯΈΑ͏
w ·ͣ1PTUHSF42-ΛཱͯΔهड़ Docker Compose Ͱ Rails ΛݐͯͯΈΑ͏ db: image: postgres:9.4
w ͍ͭͮͯ3BJMTΛཱͯΔهड़ Docker Compose Ͱ Rails ΛݐͯͯΈΑ͏ web: build: .
command: bin/rails s -p 3000 -b '0.0.0.0' environment: - DATABASE_HOST=db - DATABASE_PORT=5432 - DATABASE_USER=postgres ports: - "3000:3000" links: - db
w ىಈʂ w ৽͍͠λʔϛφϧΟϯυΛ։͍ͯʜ w σʔλϕʔεͷηοτΞοϓ Docker Compose Ͱ Rails
ΛݐͯͯΈΑ͏ $ docker-compose build $ docker-compose up $ docker-compose run web bin/rake db:setup %PDLFS.BDIJOF্ͰCVJME͕ࣦഊ͢Δ߹ɺ $ docker-machine stop default $ docker-machine up default Ͱ7.Λ࠶ىಈ͍ͯͩ͘͠͞ VQ͕ࣦഊ͢Δ߹ɺ $ docker-compose stop $ docker-compose rm -f ͰίϯςφΛফͯ͠Γ͢
w ΞΫηεͯ͠Έ·͠ΐ͏ʂ Docker Compose Ͱ Rails ΛݐͯͯΈΑ͏ $ open http://$(docker-machine
ip dev):3000 # Linux など直接 Docker が稼働しているなら $ open http://localhost:3000 EFGBVMU EPDLFSWNͳͲ खݩͷڥʹ߹Θ͍ͤͯͩ͘͞
αʔόىಈޙͷॳظԽॲཧɺFOUSZQPJOU εΫϦϓτΛ͔·ͤΔํ๏͕͋Δ ͋ΘͤͯΑΈ͍ͨ IUUQTNFEJVNDPN!LFMTFZIJHIUPXFSGSBDUVSFEBQQTDED Tips #!/bin/bash bin/rake db:create bin/rake db:migrate
bin/rake db:seed exec $@ FROM ruby:2.3.0-slim MAINTAINER dtan4 # … ENTRYPOINT ["/app/entrypoint.sh"] CMD ["bin/rails", "s]
w KXJMEFSOHJOYQSPYZ w VIRTUAL_HOSTڥมͷதΛ༻͍ͯ ϧʔςΟϯάΛ࡞ w ઌ΄Ͳͷdocker-compose.ymlʹҎԼΛՃ nginx Έ߹ΘͤΑ͏ nginx:
image: jwilder/nginx-proxy ports: - 80:80 volumes: - /var/run/docker.sock:/tmp/docker.sock:ro
w 3BJMTͷϙʔτׂΛͳ͘͢ w VIRTUAL_HOSTڥมΛՃ nginx Έ߹ΘͤΑ͏ web: build: . command:
bin/rails s -p 3000 -b '0.0.0.0' environment: - DATABASE_HOST=db - DATABASE_PORT=5432 - DATABASE_USER=postgres - VIRTUAL_HOST=docker.sokushu.dev links: - db
w ىಈʂ w ઃఆͨ͠ϗετ໊ͰΞΫηε w /etc/hostsΛॻ͖͑ͯϒϥβͰ nginx Έ߹ΘͤΑ͏ $ docker-compose
up $ curl -H "Host: docker.sokushu.dev" \ http://$(docker-machine ip docker-vm)
σϓϩΠ
None
None
Heroku w git push͢Δ͚ͩͰΞϓϦ͕σϓϩΠ͞Εɺ ࣗಈͰ63-ׂΓৼΒΕΔ w 1PTUHSF42- 3FEJT .FNDBDIFEඪ४Ͱϓ ϥάΠϯ͕༻ҙ͞Ε͍ͯΔ
w ͠Β͘લʹ%PDLFSରԠͨ͠ w खݩͰಉ͡Α͏ͳߏΛ࠶ݱͰ͖Δ w ࣗલOHJOY &MBTUJDTFBSDIͳͲݐͯΒΕͳ͍
Paus w ΠϯυωγΞޠͰʮ͘͡Βʯ w docker-compose.ymlॻ͍ͯgit push͢Δ ͚ͩͰɺΫϥυ্ʹΞϓϦέʔγϣϯ͕ ىಈ͢Δ؆қ1BB4 w $PSF04
%PDLFS EUBOQBVT
Paus ʹσϓϩΠ͠Α͏ • git checkout master w docker-compose.ymlมߋ web: image:
quay.io/dtan4/docker-service-rails:latest command: bin/rails s -p 8080 -b '0.0.0.0' environment: - DATABASE_HOST=db - DATABASE_PORT=5432 - DATABASE_USER=postgres ports: - 8080 links: - db
Paus ʹσϓϩΠ͠Α͏ w IUUQQBVTXBOUFEMZDPNͰެ։伴ొ ࣗͷϢʔβ໊ 44)ެ։伴
Paus ʹσϓϩΠ͠Α͏ • ~/.ssh/configʹҎԼΛՃ Host paus HostName paus.wantedly.com User git
Port 2222 IdentityFile ~/.ssh/id_rsa ઌ΄Ͳొͨ͠ެ։伴ͷ ϖΞͱͳΔൿີ伴
Paus ʹσϓϩΠ͠Α͏ w ϦϞʔτϦϙδτϦpausΛՃ $ git remote add paus \
paus:<username>/<repository>
Paus ʹσϓϩΠ͠Α͏ w git pushͯ͠σϓϩΠʂ $ git push paus master
Paus ʹσϓϩΠ͠Α͏ σϓϩΠ͞Εͨ ΞϓϦͷ63-
Paus ΞʔΩςΫνϟ %PDLFS $PNQPTF FUDE HJUSFDFJWFE git push docker-compose up
etcdctl set 7VMDBOE http://dtan4-rails-ffe7rf8.example.com XFC EC XFC EC
Docker PaaS / IaaS
Docker PaaS / IaaS w )FSPLVΫϩʔϯ w EPLLV BMU 'MZOO
%FJT &NQJSF w ಠࣗܗࣜ w ,VCFSOFUFT "NB[PO&$4 w Πϯϑϥ͝ͱཧ w 5VUVN %$)2JP
·ͱΊ
·ͱΊ w 8BOUFEMZͷ։ൃݱͰͷॾʹର͢Δ ղܾࡦͱͯ͠ɺ%PDLFSΛ༻͍ͨڥߏஙΛ հ͠·ͨ͠ w %PDLFS$PNQPTFΛ༻͍ͯ3BJMTͱෳͷ αʔϏεΛΈ߹ΘͤͨΞϓϦ͕ߏஙͰ͖Δ Α͏ʹͳΓ·ͨ͠ w
1BB4*BB4ͷ܈༤ׂڌ࣌