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.4k
Amazon Cloud Driveのご紹介
tondol
0
470
自家製オタクソリューションの紹介
tondol
1
480
Other Decks in Programming
See All in Programming
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
現場で役立つモデリング 超入門
masuda220
PRO
15
3.2k
イベント駆動で成長して委員会
happymana
1
320
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
ヤプリ新卒SREの オンボーディング
masaki12
0
130
Amazon Qを使ってIaCを触ろう!
maruto
0
400
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
880
cmp.Or に感動した
otakakot
2
130
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
290
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
Featured
See All Featured
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Happy Clients
brianwarren
98
6.7k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
28
2k
The Cult of Friendly URLs
andyhume
78
6k
Gamification - CAS2011
davidbonilla
80
5k
Writing Fast Ruby
sferik
627
61k
A better future with KSS
kneath
238
17k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
Why Our Code Smells
bkeepers
PRO
334
57k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
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?