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
990
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.5k
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.2k
Writing Kubenetes tools in Go
dtan4
1
3.5k
Other Decks in Technology
See All in Technology
Team Dynamicsを目指すウイングアーク1stのQAチーム
sadonosake
1
200
プロポーザルのつくり方 〜個人技編〜 / How to come up with proposals
ohbarye
4
310
AWS パートナー企業でテクニカルサポートに従事して 3年経ったので思うところをまとめてみた
kazzpapa3
1
210
Deno+JSRでパッケージを作って公開する
askua
0
110
Microsoft Intune アプリのトラブルシューティング
sophiakunii
1
390
AWS⼊社という選択肢、⾒えていますか
iwamot
2
1.1k
DatabricksにおけるLLMOpsのベストプラクティス
taka_aki
4
1.6k
10分でわかるfreeeのQA
freee
1
3.4k
ZOZOTOWNのホーム画面をパーソナライズすることの難しさと裏話を語る
f6wbl6
1
470
GraphRAGを用いたLLMによるパーソナライズド推薦の生成
naveed92
0
190
Redmine 6.0 新機能評価ガイド
vividtone
0
230
dev 補講: プロダクトセキュリティ / Product security overview
wa6sn
0
1.5k
Featured
See All Featured
Building Applications with DynamoDB
mza
90
6.1k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Making Projects Easy
brettharned
115
5.9k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
360
StorybookのUI Testing Handbookを読んだ
zakiyama
26
5.2k
RailsConf 2023
tenderlove
29
890
Build your cross-platform service in a week with App Engine
jlugia
229
18k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Designing for Performance
lara
604
68k
Writing Fast Ruby
sferik
627
61k
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ͷ܈༤ׂڌ࣌