+ All Categories
Home > Documents > PG_DOCKER

PG_DOCKER

Date post: 11-Aug-2015
Category:
Upload: david-kerr
View: 38 times
Download: 0 times
Share this document with a friend
Popular Tags:
25
Docker and Postgres A Tale of Adventure and Friendship on the high seas (or something like that)
Transcript

Docker and PostgresA Tale of Adventure and Friendship on the high seas

(or something like that)

Docker Who?

http://docker.io

Docker is an open-source engine that automates the deployment of any application as a lightweight, portable, self-sufficient container that will run virtually anywhere.

Common use cases for Docker include:

• Automating the packaging and deployment of applications • Creation of lightweight, private PAAS environments • Automated testing and continuous integration/deployment • Deploying and scaling web apps, databases and backend services

What's LXC? LXC is a userspace interface for the Linux kernel containment features. Through a powerful API and simple tools, it lets Linux users easily create and manage system or application containers.

Databases?

ORLY?

Get Setup for Docker

• Install Docker • Create a Dockerfile • Build an Image

Cloud-init > #include https://get.docker.io

Ubuntu > apt-get install lxc-docker

CentOS > yum install docker

OS X > brew install boot2docker

Installing Docker OS X

Installing Docker OS X

DockerfileFROM centos:6.4

RUN yum -y install http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-1.noarch.rpm

RUN rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

RUN yum -y install postgresql93-server pgtune

USER postgres

EXPOSE 5432

ENV PGDATA /var/lib/pgsql/data

RUN /usr/pgsql-9.3/bin/initdb

RUN pgtune -i $PGDATA/postgresql.conf > $PGDATA/local.conf

RUN echo "listen_addresses='*'" >> $PGDATA/local.conf

RUN echo "include = 'local.conf'" >> $PGDATA/postgresql.conf

RUN echo "local all all trust" > $PGDATA/pg_hba.conf

RUN echo "host all all 127.0.0.1/32 trust" >> $PGDATA/pg_hba.conf

RUN echo "host all all 0.0.0.0/0 trust" >> $PGDATA/pg_hba.conf

CMD /usr/pgsql-9.3/bin/postgres -D $PGDATA

ENV PGDATA /var/lib/pgsql/data

RUN pgtune -i $PGDATA/postgresql.conf \ > $PGDATA/local/conf

EXPOSE 5432

CMD /usr/pgsql-9.3/bin/postgres \ -D $PGDATA

Building your ImageRoberto postgresql/9.2 ‹master*› » docker build -t 'davidkerr/postgresql-9.2' . Uploading context 3.072 kB Uploading context Step 0 : FROM centos:6.4 ---> 539c0211cd76 Step 1 : RUN yum -y install http://yum.postgresql.org/9.2/redhat/rhel-6-x86_64/pgdg-centos92-9.2-6.noarch.rpm ---> Running in 749a5c4b73c4 Loaded plugins: fastestmirror Setting up Install Process Examining /var/tmp/yum-root-PgUJtE/pgdg-centos92-9.2-6.noarch.rpm: pgdg-centos92-9.2-6.noarch Marking /var/tmp/yum-root-PgUJtE/pgdg-centos92-9.2-6.noarch.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package pgdg-centos92.noarch 0:9.2-6 will be installed --> Finished Dependency Resolution

Find and Run Your ImageRoberto postgresql/9.2 ‹master*› » docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEdavidkerr/postgresql-9.2 latest 03849626fde0 34 minutes ago 460.5 MBcentos 6.4 539c0211cd76 14 months ago 300.6 MB

Roberto postgresql/9.2 ‹master*› » docker run -d -t davidkerr/postgresql-9.2e30a20b8563fa1ec5330883fddffb3e67e8efd01d26b463fafa9a2e158dd3ff7

Roberto postgresql/9.2 ‹master*› » docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESe30a20b8563f davidkerr/postgresql-9.2:latest /bin/sh -c '/usr/pgs 2 minutes ago Up 2 seconds 5432/tcp clever_newton

Benchmarking or “Yeah, but can it run Crysis?”

• Vanilla Docker • Docker with Host Volumes • Docker with Host Volumes and Host Networking • Vanilla Postgres

The System

• Digital Ocean Droplet • 512MB Ram • 20G SSD Disk • Ubuntu 13.10 • Docker 0.11.1 • PostgreSQL 9.3

The Methodology

Greg Smith’s pgbench-tools

SCRIPT="tpc-b.sql"SCALES="1 10 100"SETCLIENTS="1 2 4 8 16"SETTIMES=3

Scaling Factor

# of Clients

cswch/s With Docker

cswch/s Without Docker

Creative Uses

Multiple Postgres Versions

Roberto postgresql/9.3 ‹master*› » docker psCONTAINER ID IMAGE eba4bfad6be8 davidkerr/postgresql-9.3:latest 718f11d190ec davidkerr/postgresql-9.2:latest 01245ee047ec davidkerr/postgresql-8.4:latest

docker run -d -p 127.0.0.1:5434:5432 davidkerr/postgresql-8.4

docker run -d -p 127.0.0.1:5432:5432 davidkerr/postgresql-9.2

docker run -d -p 127.0.0.1:5433:5432 davidkerr/postgresql-9.3

Testing

• Create a reusable dataset that automatically ‘resets’ after each run

• Run multiple tests simultaneously against different containers holding the same settings and same data

Limiting Resources• Docker uses cgroups which allow you to limit access to

some resources such as CPU and Memory

docker run -c 1 # Limit CPU Shares to 1 docker run -m 1g # Limit Memory to 1GB

Code: http://bitbucket.org/davidkerr/pg_docker Other Nonsense: @davidkerr

Thanks