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
Security-JAWS【第35回】勉強会クラウドにおけるマルウェアやコンテンツ改ざんへの対策
4su_para
0
170
複雑なState管理からの脱却
sansantech
PRO
1
130
障害対応指揮の意思決定と情報共有における価値観 / Waroom Meetup #2
arthur1
5
470
ノーコードデータ分析ツールで体験する時系列データ分析超入門
negi111111
0
410
【令和最新版】AWS Direct Connectと愉快なGWたちのおさらい
minorun365
PRO
5
750
マルチモーダル / AI Agent / LLMOps 3つの技術トレンドで理解するLLMの今後の展望
hirosatogamo
37
12k
ExaDB-D dbaascli で出来ること
oracle4engineer
PRO
0
3.8k
Taming you application's environments
salaboy
0
180
B2B SaaS × AI機能開発 〜テナント分離のパターン解説〜 / B2B SaaS x AI function development - Explanation of tenant separation pattern
oztick139
2
220
Amplify Gen2 Deep Dive / バックエンドの型をいかにしてフロントエンドへ伝えるか #TSKaigi #TSKaigiKansai #AWSAmplifyJP
tacck
PRO
0
370
ISUCONに強くなるかもしれない日々の過ごしかた/Findy ISUCON 2024-11-14
fujiwara3
8
860
誰も全体を知らない ~ ロールの垣根を超えて引き上げる開発生産性 / Boosting Development Productivity Across Roles
kakehashi
1
220
Featured
See All Featured
How GitHub (no longer) Works
holman
310
140k
Designing Experiences People Love
moore
138
23k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Faster Mobile Websites
deanohume
305
30k
Gamification - CAS2011
davidbonilla
80
5k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
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ͷ܈༤ׂڌ࣌