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
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.1k
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
180
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
540
受け取る人から提供する人になるということ
little_rubyist
0
180
Quine, Polyglot, 良いコード
qnighy
4
610
Amazon Qを使ってIaCを触ろう!
maruto
0
370
Macとオーディオ再生 2024/11/02
yusukeito
0
320
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2k
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
270
C#/.NETのこれまでのふりかえり
tomokusaba
1
180
Dev ContainersとGitHub Codespacesの素敵な関係
ymd65536
1
140
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
Featured
See All Featured
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
How to Think Like a Performance Engineer
csswizardry
20
1.1k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
YesSQL, Process and Tooling at Scale
rocio
168
14k
Side Projects
sachag
452
42k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
42
2.2k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
43
6.8k
Docker and Python
trallard
40
3.1k
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?