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
460
自家製オタクソリューションの紹介
tondol
1
470
Other Decks in Programming
See All in Programming
offers_20241022_imakiire.pdf
imakurusu
2
360
Sidekiqで実現する 長時間非同期処理の中断と再開 / Pausing and Resuming Long-Running Asynchronous Jobs with Sidekiq
hypermkt
6
2.7k
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
390
Golang と Erlang
taiyow
8
1.9k
カラム追加で増えるActiveRecordのメモリサイズ イメージできますか?
asayamakk
4
1.5k
讓數據說話:用 Python、Prometheus 和 Grafana 講故事
eddie
0
350
CPython 인터프리터 구조 파헤치기 - PyCon Korea 24
kennethanceyer
0
240
デプロイを任されたので、教わった通りにデプロイしたら障害になった件 ~俺のやらかしを越えてゆけ~
techouse
52
32k
Vue.js学習の振り返り
hiro_xre
2
130
2万ページのSSG運用における工夫と注意点 / Vue Fes Japan 2024
chinen
3
1.3k
Nuxt UI Pro、NuxtHub、Nuxt Scripts、Nuxtエコシステムをふんだんに利用して開発するコーポレートサイト@Vue Fes Japan 2024
shingangan
3
880
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
910
Featured
See All Featured
Documentation Writing (for coders)
carmenintech
65
4.4k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
664
120k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Measuring & Analyzing Core Web Vitals
bluesmoon
1
39
How to Think Like a Performance Engineer
csswizardry
19
1.1k
Product Roadmaps are Hard
iamctodd
PRO
48
10k
Making Projects Easy
brettharned
115
5.9k
Code Review Best Practice
trishagee
64
17k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
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?