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
Amazon CloudWatch Network Monitor のススメ
yuki_ink
1
210
あなたの知らない Function.prototype.toString() の世界
mizdra
PRO
3
1k
AWS Lambda のトラブルシュートをしていて思うこと
kazzpapa3
2
200
ノーコードデータ分析ツールで体験する時系列データ分析超入門
negi111111
0
430
OCI Vault 概要
oracle4engineer
PRO
0
9.8k
SREが投資するAIOps ~ペアーズにおけるLLM for Developerへの取り組み~
takumiogawa
4
1k
心が動くエンジニアリング ── 私が夢中になる理由
16bitidol
0
110
組織成長を加速させるオンボーディングの取り組み
sudoakiy
3
290
【Pycon mini 東海 2024】Google Colaboratoryで試すVLM
kazuhitotakahashi
2
590
データプロダクトの定義からはじめる、データコントラクト駆動なデータ基盤
chanyou0311
3
360
インフラとバックエンドとフロントエンドをくまなく調べて遅いアプリを早くした件
tubone24
1
440
初心者向けAWS Securityの勉強会mini Security-JAWSを9ヶ月ぐらい実施してきての近況
cmusudakeisuke
0
140
Featured
See All Featured
Building Adaptive Systems
keathley
38
2.3k
Bash Introduction
62gerente
608
210k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Writing Fast Ruby
sferik
627
61k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
The Language of Interfaces
destraynor
154
24k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
What's in a price? How to price your products and services
michaelherold
243
12k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
380
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ͷ܈༤ׂڌ࣌