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
創造的活動から切り拓く新たなキャリア 好きから始めてみる夜勤オペレーターからSREへの転身
yjszk
1
130
ドメインイベント増えすぎ問題
h0r15h0
1
170
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
140
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
700
Stackless и stackful? Корутины и асинхронность в Go
lamodatech
0
690
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
290
20年もののレガシープロダクトに 0からPHPStanを入れるまで / phpcon2024
hirobe1999
0
110
Jakarta EE meets AI
ivargrimstad
0
230
テストコード文化を0から作り、変化し続けた組織
kazatohiei
2
1.5k
As an Engineers, let's build the CRM system via LINE Official Account 2.0
clonn
1
670
快速入門可觀測性
blueswen
0
330
The rollercoaster of releasing an Android, iOS, and macOS app with Kotlin Multiplatform | droidcon Italy
prof18
0
150
Featured
See All Featured
Testing 201, or: Great Expectations
jmmastey
40
7.1k
Bash Introduction
62gerente
608
210k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Raft: Consensus for Rubyists
vanstee
137
6.7k
Designing for humans not robots
tammielis
250
25k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Embracing the Ebb and Flow
colly
84
4.5k
Building Your Own Lightsaber
phodgson
103
6.1k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.3k
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?