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
1k
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
7.1k
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
社内イベント管理システムを1週間でAKSからACAに移行した話し
shingo_kawahara
0
180
20241214_WACATE2024冬_テスト設計技法をチョット俯瞰してみよう
kzsuzuki
3
440
組織に自動テストを書く文化を根付かせる戦略(2024冬版) / Building Automated Test Culture 2024 Winter Edition
twada
PRO
11
3.3k
開発生産性向上! 育成を「改善」と捉えるエンジニア育成戦略
shoota
1
230
私なりのAIのご紹介 [2024年版]
qt_luigi
1
120
権威ドキュメントで振り返る2024 #年忘れセキュリティ2024
hirotomotaguchi
2
730
KubeCon NA 2024 Recap: How to Move from Ingress to Gateway API with Minimal Hassle
ysakotch
0
200
マイクロサービスにおける容易なトランザクション管理に向けて
scalar
0
110
10個のフィルタをAXI4-Streamでつなげてみた
marsee101
0
160
Oracle Cloud Infrastructure:2024年12月度サービス・アップデート
oracle4engineer
PRO
0
160
社外コミュニティで学び社内に活かす共に学ぶプロジェクトの実践/backlogworld2024
nishiuma
0
250
MLOps の現場から
asei
6
630
Featured
See All Featured
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Bash Introduction
62gerente
608
210k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
Making the Leap to Tech Lead
cromwellryan
133
9k
Designing for humans not robots
tammielis
250
25k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.5k
BBQ
matthewcrist
85
9.4k
KATA
mclloyd
29
14k
Mobile First: as difficult as doing things right
swwweet
222
9k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.3k
Side Projects
sachag
452
42k
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ͷ܈༤ׂڌ࣌