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
tondol
June 24, 2015
Programming
1
2.7k
ドはDockerのド
tondol.comをDocker運用化したときの知見
tondol
June 24, 2015
Tweet
Share
More Decks by tondol
See All by tondol
ちいさく始めるレイヤードアーキテクチャ
tondol
7
1.8k
RxSwift 3.3.0: Observable のフレンズが増えました!!
tondol
2
2.5k
Amazon Cloud Driveのご紹介
tondol
0
470
自家製オタクソリューションの紹介
tondol
1
480
Other Decks in Programming
See All in Programming
The Efficiency Paradox and How to Save Yourself and the World
hollycummins
1
450
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
940
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
260
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
250
Effective Signals in Angular 19+: Rules and Helpers
manfredsteyer
PRO
0
110
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
4
290
創造的活動から切り拓く新たなキャリア 好きから始めてみる夜勤オペレーターからSREへの転身
yjszk
1
130
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
150
Haze - Real time background blurring
chrisbanes
1
510
採用事例の少ないSvelteを選んだ理由と それを正解にするためにやっていること
oekazuma
2
1k
テストコードのガイドライン 〜作成から運用まで〜
riku929hr
5
670
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
3
480
Featured
See All Featured
How to Ace a Technical Interview
jacobian
276
23k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
How to train your dragon (web standard)
notwaldorf
88
5.7k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
Into the Great Unknown - MozCon
thekraken
33
1.5k
How GitHub (no longer) Works
holman
311
140k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
It's Worth the Effort
3n
183
28k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
Imperfection Machines: The Place of Print at Facebook
scottboms
266
13k
Transcript
W8LT#03 υDockerͷυ @tondol 2015-06-24 (Wed.)
Self Introduction @tondol ܭࢉֶઐ߈M2 ˓˓ݚڀࣨ ࠓिͷLTϥϒϥΠϒʂ͡Ό͋Γ·ͤΜ िʹߦ͖·͢ ͦͷ࣍ͷिେࡕ……
ൃ
ൃ • 500ԁVPSʢDTIʣͷੑೳ͕ඍົ͔ͩΒ 1000ԁVPSʢConoHaʣʹҠߦ͍ͨ͠ • ੈؒͷτϨϯυDockerͱͷ͜ͱ • ࠓޙͷͨΊʹDockerӡ༻ʹ͠Α͏ • Infrastructure
as Code!!
Infrastructure as Code • ΞϓϦΛӡ༻͢ΔڥΛίʔυͰهड़ • ίʔυΛॲཧܥͰ࣮ߦ͢Ε ڥ͕͢Δ • ଐਓԽ͞Εͨڥߏங͔Βͷղ์
• ϛεͷͳ͍ΦϖϨʔγϣϯ • εέʔϥϒϧ
Docker • ԾԽϓϥοτϑΥʔϜ • Πϯϑϥʹ͓͚Δࣄ্࣮ͷඪ४ • ԾϚγϯͷঢ়ଶΛΠϝʔδԽ ͋Δ͍Πϝʔδ͔ΒԾϚγϯΛ࡞ • DockerfileΛݩʹڥΛϏϧυ
• LXCٕज़ʹΑΔޮͷߴ͍ԾԽ • ඪ४ن͕֨Ͱ͖ΔͬΆ͍ʁ https://www.opencontainers.org/
έʔεελσΟ
Dockerӡ༻Խͷର • ΣϒΞϓϦ – www.tondol.com : ͱΜͲΔͲͬͱ͜Ή – tmp.tondol.com : koeradi, SOretter
– anime.tondol.com : NicoAnime – kako.tondol.com : NicoKako – oretter.tondol.com : Oretter • ͦͷଞTwitter BOTͳͲ
Dockerӡ༻Խͷର • tondol.com
ϨΨγʔڥͷҰྫ • ίϚϯυඞཁʹͳͬͨΒyumͰೖΕΔ – ͨ·ʹιʔε͔ΒϏϧυ͢Δ • Εͦ͏ͳઃఆؾ͕͍ͨΒϒϩάʹϝϞ – ͪΖΜυΩϡϝϯτԽ͞Ε͍ͯͳ͍ઃఆ͋Δ •
εΫϦϓτͱઃఆϑΝΠϧ͕͍ࠞͬͯ͟Δ • ӬଓԽσʔλ͕εΫϦϓτͱಉ͡σΟϨΫτϦʹ͋Δ • ϝʔϧαʔόʔͷઃఆํ๏ͱ͔͏Εͨ • ঢ়ଶ͕มԽ͢Δʹϛϡʔλϒϧ • ࠓͷঢ়ଶʹ͢ΔͨΊͷϨγϐ͕ࣦΘΕ͍ͯΔ • ෆඞཁͳίϚϯυϥΠϒϥϦ͕ͨ͘͞Μ͋Δ
DockerಋೖʹΑΔϝϦοτ • ڥͷ࠶ݱ͕ΊͬͪΌ؆୯ʹͳΔ • ·ͱͳߏʹ͢Εεέʔϧ͘͢͠ͳΔ • ίʔυԽ͞Ε͍ͯΔ҆৺ײ • ֤ΞϓϦͷڥΛͯ͠ηοτΞοϓͰ͖Δ •
࠷ॳಋೖ͕ΊͪΌେม͕ͩɺ Ұྃ͢Εͦͷޙָ͕Ͱ͖Δʁ
DockerಋೖΛ્ΉཁҼ • Gitཧ͞Ε͍ͯͳ͍ιʔείʔυ • εΫϦϓτʹϕλॻ͖͞Ε͍ͯΔઃఆ • ແ࡞ʹஔ͞ΕΔӬଓԽσʔλ • υΩϡϝϯτԽ͞Ε͍ͯͳ͍ ίϚϯυɾϥΠϒϥϦͷґଘঢ়گ
• ΞϓϦͷվम͔Β࢝ΊΔඞཁ͕͋Δ
ΞϓϦվमͷํ • ιʔεΛGitཧԼʹஔ͖ɺ GitHubBitBucketʹΞοϓϩʔυ – BitBucketඇެ։ϦϙδτϦ͕ແྉ • ઃఆϑΝΠϧΛ – JSON/YAML/.envͳͲΛ͏ • ӬଓԽσʔλͷอଘઌΛઃఆՄೳʹ
• BundlerʢRubyʣɾComposerʢPHPʣΛ ֤ΞϓϦʹಋೖ͢Δ
ಋೖલ VPS (CentOS) Apache mod_php tmp. www. oretter. anime. kako.
Ruby MySQL Crond ఆظతʹRuby εΫϦϓτΛୟ͘ VirtualHostઃఆ
ಋೖޙ anime. VPS (CoreOS) Docker nginx Ruby Crond php-fpm CentOS
nginx CentOS MySQL CentOS
ίϯςφಉ࢜ͷґଘ base data-kako data-anime data-tmp data-mysql nginx www tmp oretter
anime kako mysql postfix ɿΞϓϦίϯςφʗਫ৭ɿσʔλίϯςφ ҹɿProxyઌͷࢀর ࠠҹɿσʔλίϯςφͷࢀর
࣮ৄࡉ
Dockerͷ֓೦ DockerHub ϩʔΧϧڥ Πϝʔδ আ ίϯςφ Dockerfile pull build
run commit push rm rmi stop, start
ίϯςφ࿈ܞ App Container • ڥม • /etc/hostsϑΝΠϧ • /home/tondol/data DB
Container Data Container /opt --link --volume-from -v /opt
DockerίϚϯυ docker pull centos:centos6 docker build nginx docker run -d
--name nginx1 nginx docker ps docker stop docker images docker rm/rmi docker push DockerHub্ͷެࣜΠϝʔδ DockerfileͷॴΛࢦఆ ίϯςφ໊ʗΠϝʔδΛࢦఆ
࣮ৄࡉ 1. VPSʹCoreOSΛΠϯετʔϧ CoreOS: Dockerϗετ༻ͷܰྔOS ConoHaʹCoreOSΛΠϯετʔϧ͢Δํ๏ https://www.conoha.jp/conoben/archives/2071 ্هΛࢀߟʹΠϝʔδΛΠϯετʔϧ cloud-config.yamlͷฤूͱ͔
࣮ৄࡉ 2. baseΠϝʔδΛ࡞͢Δ ֤ίϯςφʹඞཁͳॲཧܥͳͲΛΠϯετʔϧͨ͠ ϕʔεΠϝʔδΛ༻ҙ͠ɺଞίϯςφͷϏϧυΛߴԽ FROM centos:centos6 MAINTAINER tondol
... RUN rpm -‐Uvh http://dl.fedoraproject.org/pub/epel/6/i386/epel-‐ release-‐6-‐8.noarch.rpm RUN rpm -‐Uvh http://rpms.famillecollet.com/enterprise/remi-‐release-‐6.rpm RUN yum -‐y install initscripts sudo passwd RUN yum -‐y install openssh openssh-‐clients openssh-‐server RUN yum -‐y install python-‐setuptools vim wget ... # ruby RUN yum -‐y groupinstall 'Development tools' ... RUN git clone https://github.com/sstephenson/ruby-‐build.git && \ ruby-‐build/install.sh && ruby-‐build 2.1.5 /usr/local && \ gem update -‐-‐system && gem install bundler pry -‐-‐no-‐document ...
࣮ৄࡉ 3. MySQL༻ɾσʔλ༻ίϯςφΛ࡞͢Δ MySQL༻ίϯςφ σʔλ༻ίϯςφ FROM tondol/base:latest MAINTAINER tondol
# supervisor ADD supervisord.conf /etc/supervisord/conf.d/service.conf # mysql RUN echo "NETWORKING=yes" > /etc/sysconfig/network RUN mv /etc/my.cnf /etc/my.cnf.orig ADD my.cnf /etc/my.cnf ADD mysqld.sh /home/tondol/mysqld.sh RUN chmod +x /home/tondol/mysqld.sh EXPOSE 2222 3306 CMD ["/usr/bin/supervisord"] FROM busybox VOLUME /opt CMD /bin/true
࣮ৄࡉ 4. ΞϓϦվम / 5. ΞϓϦͷίϯςφ࡞ Dockerfile FROM tondol/base:latest
MAINTAINER tondol ... # nicokako ADD dummy /tmp/dummy RUN git clone https://github.com/tondol/NicoKako.git /home/tondol/www && \ cd /home/tondol/www && git submodule update -‐-‐init && \ cd /home/tondol/www/ruby && bundle install ADD nicokako-‐config.yml /home/tondol/www/config.yml ADD .htpasswd /home/tondol/www/.htpasswd RUN chmod o+x /home/tondol && \ chown -‐R tondol:tondol /home/tondol/www && \ chmod o+w /home/tondol/www/config.yml ...
࣮ৄࡉ 4. ΞϓϦվम / 5. ΞϓϦͷίϯςφ࡞ Supervisord.conf [supervisord] nodaemon=true
[program:sshd] command=/usr/sbin/sshd -‐D autostart=true autorestart=true [program:nginx] command=/usr/sbin/nginx -‐c /etc/nginx/nginx.conf -‐g "daemon off;" autostart=true #autorestart=true [program:php-‐fpm] command=/home/tondol/php-‐fpm.sh autostart=true #autorestart=true ...
࣮ৄࡉ 6. ϑϩϯτ༻ίϯςφΛ࡞Δ nginx.conf server {
listen 80; server_name oretter.tondol.com; return 301 https://$host$request_uri; #location / { # proxy_pass http://__ORETTER_HOST__:__ORETTER_PORT__/; #} } server { listen 443; server_name oretter.tondol.com; ssl on; ssl_certificate /etc/pki/tls/certs/oretter.tondol.com.server.crt; ssl_certificate_key /etc/pki/tls/certs/oretter.tondol.com.server.key; proxy_set_header Host $http_host; proxy_set_header X-‐Forwarded-‐For $proxy_add_x_forwarded_for; location / { proxy_pass http://__ORETTER_HOST__:__ORETTER_PORT__/; } }
࣮ৄࡉ 7. docker-composeΛಋೖ docker-compose.yml mysql: build: mysql
volumes_from: -‐ datamysql ports: -‐ 12222:2222 -‐ 13306:3306 environment: MYSQL_USER: docker MYSQL_PASSWORD: xxxx nginxkako: build: nginx-‐kako volumes_from: -‐ datakako ports: -‐ 12272:2222 -‐ 10110:80 -‐ 10473:443 links: -‐ mysql:mysql environment: MYSQL_USER: docker MYSQL_PASSWORD: xxxx
ิ • DockerfileԽ – ຊདྷతʹ1ϓϩηεʗ1ίϯςφ – Supervisorͱ͍͏πʔϧͰϚϧνϓϩηεԽ – ઃఆϑΝΠϧADDσΟϨΫςΟϒͰίϐʔ •
docker-compose.ymlͷهड़ – αʔϏε໊ͱରΠϝʔδͷରԠ – ىಈ࣌ͷΦϓγϣϯ • σʔλϘϦϡʔϜ • ϙʔτͷରԠ • ίϯςφؒͷϦϯΫ • ڥม
ิ • ίϯςφؒͷϦϯΫ – ࣮ߦ࣌ͷΦϓγϣϯͰ༩͑ΒΕΔ – ίϯςφىಈ࣌ʹڥมͰ͞ΕΔ – ίϯςφؒͷϦϯΫΛ ίϯςφͷઃఆϑΝΠϧʹө͢Δʹʁ • Supervisor͔ΒγΣϧεΫϦϓτΛ࣮ߦ •
γΣϧεΫϦϓτ͕ઃఆϑΝΠϧதͷ ಛఆจࣈྻΛڥมͰஔ͖͑Δ • ઃఆϑΝΠϧΛಡΈࠐΉαʔϏεΛ࠶ىಈ
·ͱΊ
՝ • Ϗϧυʹֻ͔Δ࣌ؒ – base͔ΒϏϧυ͢͠ͱΊͬͪΌֻ͔࣌ؒΔ • σϓϩΠ࣌ͷμϯλΠϜ – build -> stop ->
restartͷؒʹμϯ͢Δ – Blue Green Deployment͢Δʹʁ • ίϯςφͷϩάΛू͢Δʹʁ • ࢮ׆ࢹ
·ͱΊ • tondol.comΛDockerӡ༻Խ͠·ͨ͠ – ݟΛڞ༗͠·ͨ͠ • Docker is ศར – पลπʔϧ͕ͨ͘͞Μ͋Δ – ֮͑Δ͜ͱ͕ͨ͘͞Μ͋Δ
• Dockerॳ৺ऀʹͳΓ·ͨ͠ – ݟΛ͘Ε
Q AND A?