Docker Workshop - Meetupfiles.meetup.com/2979972/Docker_Workshop-20140318.pdf · 1 Docker Workshop...
Transcript of Docker Workshop - Meetupfiles.meetup.com/2979972/Docker_Workshop-20140318.pdf · 1 Docker Workshop...
2
So what is this Docker?
An open source project to pack, ship and run any application as a lightweight container
3
What do you have to say for yourself?
Static website
Web frontend
User DB
Queue Analytics DB
Background workers
API endpoint
nginx 1.5 + modsecurity + openssl + bootstrap 2
postgresql + pgv8 + v8
hadoop + hive + thrift + OpenJDK
Ruby + Rails + sass + Unicorn
Redis + redis-sentinel
Python 3.0 + celery + pyredis + libcurl + ffmpeg + libopencv + nodejs + phantomjs
Python 2.7 + Flask + pyredis + celery + psycopg + postgresql-client
Development VM
QA server
Public Cloud
Disaster recovery
Contributor’s laptop
Production Servers
The ChallengeM
ultp
licity
of S
tack
s
Mul
tplic
ity o
f har
dwar
e
envi
ronm
ents
Production Cluster
Customer Data Center
Do services an d apps intera ct
appropriately ?
Can I migrate sm
oothly and quickly?
The Matrix From Hell
Static website
Web frontend
Background workers
User DB
Analytics DB
Queue
Development
VMQA Server
Single Prod
ServerOnsite Cluster Public Cloud
Contributor’s
laptop
Customer
Servers
? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
Mul
tplic
ity o
f Goo
ds
Mul
tpili
city
of m
etho
ds fo
r
tran
spor
tng/
stor
ing
Do I w
orry ab out how good s interact
(e.g. cofee be ans next to s pices)
Can I transpo rt quickly and smoothly
(e.g. from boa t to train to t ruck)
Cargo Transport Pre-1960
? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
? ? ? ? ? ? ?
Also a matrix from hell
Mul
tplic
ity o
f Goo
ds
Mul
tplic
ity o
f met
hods
for
tran
spor
tng/
stor
ing
Do I w
orry abo ut how good s interact
(e.g. cofee be ans next to sp ices)Can I transpor t quickly and sm
oothly
(e.g. from boa t to train to tr uck)
Solution: Intermodal Shipping Container
…in between, can be loaded and unloaded,
stacked, transported efficiently over long
distances, and transferred from one mode of
transport to another
A standard container that is loaded with
virtually any goods, and stays sealed until
it reaches final delivery.
Static website Web frontend User DB QueueAnalytics DB
Development VMQA server Public Cloud
Contributor’s laptop
Docker is a shipping container system for code M
ultp
licity
of S
tack
sM
ultp
licity
of h
ardw
are
envi
ronm
ents
Production ClusterCustomer Data Center
Do services an d apps intera ct
appropriately?
Can I migrate sm
oothly and quickly
…that can be manipulated using standard
operations and run consistently on virtually any
hardware platform
An engine that enables any payload to be
encapsulated as a lightweight, portable,
self-sufficient container…
Static website
Web frontend
Background workers
User DB
Analytics DB
Queue
Development
VMQA Server
Single Prod
ServerOnsite Cluster Public Cloud
Contributor’s
laptop
Customer
Servers
Docker eliminates the matrix from Hell
11
Caveat hacker
12
The deets● Requirements
● x86 ISA● Linux Kernel 3.2+, or 2.6.32+ for RHEL/Fedora
● Isolation – a docker container has its own:● Process namespace● Network interface● Root user● Upstart / systemd (optional)
● But it doesn't have its own:● Hypervisor● Kernel
13
Process to build a Docker Container
Dockerfile Build
Docker
Host OS
Container DockerIndex
index.docker.io
14
The Dockerfile● Really basic example from http://goo.gl/Z2OWXN
FROM ubuntuMAINTAINER [email protected] aptkey adv keyserver keyserver.ubuntu.com recvkeys \ B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precisepgdg main" \ > /etc/apt/sources.list.d/pgdg.listRUN aptget updateRUN aptget y q install pythonsoftwareproperties softwarepropertiescommonRUN aptget y q install postgresql9.3 postgresqlclient9.3 \ postgresqlcontrib9.3USER postgresRUN /etc/init.d/postgresql start &&\ psql command "CREATE USER docker WITH SUPERUSER PASSWORD 'docker';" &&\ createdb O docker dockerRUN echo "host all all 0.0.0.0/0 md5" \ >> /etc/postgresql/9.3/main/pg_hba.confRUN echo "listen_addresses='*'" >> /etc/postgresql/9.3/main/postgresql.confEXPOSE 5432VOLUME ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]CMD ["/usr/lib/postgresql/9.3/bin/postgres", "D", \ "/var/lib/postgresql/9.3/main", "c", \ "config_file=/etc/postgresql/9.3/main/postgresql.conf"]
15
Let's build that on RHEL● Installation procedure for RHEL 6.5● Get key from
● http://github.com/jason-callaway/openstackdc### AWS instances are preregistered for updates[root@localhost]# yum update y[root@localhost]# wget https://mirror.us.leaseweb.net/epel/6/x86_64/epelrelease68.noarch.rpm[root@localhost]# yum install y ./epelrelease68.noarch.rpm[root@localhost]# yum install y dockerio git postgresql[root@localhost]# service docker start; chkconfig docker on[root@localhost]# git clone http://github.com/jasoncallaway/openstackdc[root@localhost]# cd openstackdc[root@localhost]# ln s Dockerfile_ubuntupostgres Dockerfile[root@localhost]# docker build t <yourname>_pg .### Look at the new image you've made[root@localhost]# docker images### Now let's run it[root@localhost]# docker run d name pg <yourname>_pg### Check the running containers[root@localhost]# docker ps[root@localhost]# docker inspect pg
16
Now let's make one based on Fedora
FROM fedoraMAINTAINER [email protected] yum install y postgresqlserverUSER postgresRUN /bin/initdb D /var/lib/pgsql/dataRUN /usr/bin/pg_ctl start D /var/lib/pgsql/data s o "p 5432" w t 300 &&\ /bin/psql command "CREATE USER docker WITH SUPERUSER PASSWORD 'docker';" &&\ /bin/createdb O docker dockerRUN echo "host all all 0.0.0.0/0 md5" >> /var/lib/pgsql/data/pg_hba.confRUN echo "listen_addresses='*'" >> /var/lib/pgsql/data/postgresql.confEXPOSE 5432VOLUME ["/var/lib/pgsql/data"]CMD ["/bin/postgres", "D", "/var/lib/pgsql/data", "c", "config_file=/var/lib/pgsql/data/postgresql.conf"]