37

Vagrant move over, here is Docker

Embed Size (px)

DESCRIPTION

Developers need to be able to run an application on an environment as closely matched to production as possible. We can already do this through Vagrant.The problem with Vagrant is that it is slow and takes a lot of resources both in cpu and space. Docker doesn't have this problem and gives you a tool to create hundreds of different application environments on the same machine and distribute them through a registry. As Git replaced SVN, so has Docker replaced vagrant for application environment setups.Leave the future behind, own today (like a boss).

Citation preview

Page 1: Vagrant move over, here is Docker
Page 2: Vagrant move over, here is Docker

PHPBenelux Wednesday, October 22, 2014

Page 3: Vagrant move over, here is Docker
Page 4: Vagrant move over, here is Docker

* Vagrant is a Manager for VMs* Vagrant is a Manager for VMs

* Vagrant is AWESOME!* Vagrant is AWESOME!

* Vagrant Simplified our lives tremendously* Vagrant Simplified our lives tremendously

Page 5: Vagrant move over, here is Docker
Page 6: Vagrant move over, here is Docker

● * server virtualization is slow* server virtualization is slow● * hard to distribute (compared to docker)* hard to distribute (compared to docker)

● * base box + vagrant provision (puppet, ansible, * base box + vagrant provision (puppet, ansible, saltstack)saltstack)

● * vagrant package --base [hash] --output * vagrant package --base [hash] --output [boxname.box] [boxname.box]

● * fixed memory consumption* fixed memory consumption

Page 7: Vagrant move over, here is Docker

● * disk space hog* disk space hog● * service install / remove trials are * service install / remove trials are

expensiveexpensive● * destroy + up is coffee time* destroy + up is coffee time● * hypervisor abstracts an entire device* hypervisor abstracts an entire device● * expensive emulating virtual hardware* expensive emulating virtual hardware

Page 8: Vagrant move over, here is Docker

But it ain't good for ...But it ain't good for ...

* Excellent for manual testing* Excellent for manual testing* Excellent for Selenium Grid* Excellent for Selenium Grid* Excellent for taking an OS test drive* Excellent for taking an OS test drive* Excellent for running non linux apps* Excellent for running non linux apps* And probably a lot more!* And probably a lot more!

It ain't all bad!It ain't all bad!

Page 9: Vagrant move over, here is Docker

Running or Running or developingdeveloping

a Linux a Linux applicationapplication

Page 10: Vagrant move over, here is Docker

Purring power!!!Purring power!!!

Page 11: Vagrant move over, here is Docker

"Docker is an open platform for developers "Docker is an open platform for developers and sysadmins to build, ship, and run and sysadmins to build, ship, and run distributed applications."distributed applications."

Page 12: Vagrant move over, here is Docker

* dedicated tool to help build stable application * dedicated tool to help build stable application environments environments* distribute those environments easily* distribute those environments easily* low cost install / remove services* low cost install / remove services

Page 13: Vagrant move over, here is Docker

> whoami_* built on top of LXC (container technology). * built on top of LXC (container technology).

* uses file system, storage, CPU, RAM, and so on* uses file system, storage, CPU, RAM, and so on

* just abstract the operating system kernel* just abstract the operating system kernel

Page 14: Vagrant move over, here is Docker

> ls effect_* more efficient in resource terms* more efficient in resource terms

* leave behind 99.9% VM junk* leave behind 99.9% VM junk

* 4-6 times more server application instances* 4-6 times more server application instances

Page 15: Vagrant move over, here is Docker

Terminology

* Image

* Container

* Repository

* Registry

Page 16: Vagrant move over, here is Docker
Page 17: Vagrant move over, here is Docker
Page 18: Vagrant move over, here is Docker

We don't need no stinking

Page 19: Vagrant move over, here is Docker

We Need a Dockerfile

FROM debian:wheezy

MAINTAINER Nick Belhomme, [email protected]

RUN apt-get update

RUN apt-get install -y apache2 wget vim curl

# expose the portsEXPOSE 80

FROM nickbelhomme/apache

RUN a2enmod rewrite

RUN apt-get install -y php5-common libapache2-mod-php5 php5-cli php5-intl php5-curl php5-pgsql

ADD dev/apache/application.conf /etc/apache2/sites-available/application.confRUN a2ensite application.conf

nickbelhomme/apache nickbelhomme/foo

Page 20: Vagrant move over, here is Docker
Page 21: Vagrant move over, here is Docker

Actually we Need multiple Dockerfiles

1 FOR APACHE (+ PHP)

1 FOR a DB

1 FOR NODE

1 FOR VARNISH

1 FOR MEMCACHED

1 FOR REDIS

1 FOR ...

Or use the Registry for pre-build images

1 PER Application

Page 22: Vagrant move over, here is Docker

Forge togetherUsing Containers

docker run -d -P --name postgres nickbelhomme/postgres docker run -d --link postgres:postgres --name applicationFoo -v /home/nick/vhosts/foo/application:/var/www/vhosts/local.foo.com -p 49101:80 nickbelhomme/foo /usr/sbin/apachectl -D FOREGROUND

Page 23: Vagrant move over, here is Docker

> docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

e39 node:latest "grunt watch" 5 days ago Up 2 seconds applicationFoo-grunt a2d applicationFoo:latest "apachectl 2 weeks ago Up 2 seconds 49101->80/tcp applicationFoo bda postgres:latest "/usr/lib/postgresql 4 weeks ago Up 3 seconds 49155->5432/tcp fooBar/postgres,applicationFoo/postgres,gooBar/postgres,postgres

http://local.foo.com:49101

/etc/hosts => Docker0-ip local.foo.com

Page 24: Vagrant move over, here is Docker

> docker run --rm --link postgres:postgres nickbelhomme/postgres env

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binHOSTNAME=0bda3edb485ePOSTGRES_PORT=tcp://10.66.33.13:5432POSTGRES_PORT_5432_TCP=tcp://10.66.33.13:5432POSTGRES_PORT_5432_TCP_ADDR=10.66.33.13POSTGRES_PORT_5432_TCP_PORT=5432POSTGRES_PORT_5432_TCP_PROTO=tcpPOSTGRES_NAME=/loving_colden/postgresHOME=/var/lib/postgresql

<?php host=' . getenv('POSTGRES_PORT_5432_TCP_ADDR') ?>

Page 25: Vagrant move over, here is Docker

> docker logs –follow applicationFoo-grunt

Done, without errors.Completed in 0.438s at Wed Oct 15 2014 19:06:28 GMT+0000 (UTC) - Waiting...OK>> File "rawJs/foo/form.js" changed.

Running "concat:js" (concat) taskFile "./public/js/source.js" created.

Done, without errors.Completed in 0.458s at Wed Oct 15 2014 19:11:34 GMT+0000 (UTC) - Waiting...Running "watch" task

Page 26: Vagrant move over, here is Docker

> docker start postgres applicationFoo applicationFoo-grunt> docker stop postgres applicationFoo applicationFoo-grunt

#!/bin/bashif [ "$1" = "start" ]; thendocker start postgres applicationFoo applicationFoo-gruntexitfiif [ "$1" = "db" ]; thendocker run --rm --link postgres:postgres nickbelhomme/postgres envexitfiif [ "$1" = "grunt" ]; thendocker logs --follow applicationFoo-gruntexitfi

> ./project start> ./project stop> ./project grunt> ./project ...

Page 27: Vagrant move over, here is Docker

Team distribution

Page 28: Vagrant move over, here is Docker

> docker login

> docker push nickbelhomme/postgres

> docker pull nickbelhomme/postgres

> docker run [options] [container]

> develop

Page 29: Vagrant move over, here is Docker

Now some bad ass Super hero

Tips

Page 30: Vagrant move over, here is Docker

> docker build -t nickbelhomme/foo .

> docker run --name applicationFoo

> docker run –rm ...

> docker run -w /var/www/vhosts/local.foo.com

> docker run -i -t nickbelhomme/foo /bin/bash

> docker run -v hostDir:containerDir

> docker build –no-cache=true

Page 31: Vagrant move over, here is Docker

> docker rm $(docker ps -a -q)

> docker rmi $(docker images -a -q)

> docker rmi $(docker images -q --filter "dangling=true")

Page 32: Vagrant move over, here is Docker

> cat /etc/default/docker

# Docker Upstart and SysVinit configuration file

# Customize location of Docker binary (especially for development testing).#DOCKER="/usr/local/bin/docker"

# Use DOCKER_OPTS to modify the daemon startup options.#DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"DOCKER_OPTS="—bip=10.66.33.10/24"

# If you need Docker to use an HTTP proxy, it can also be specified here.#export http_proxy="http://127.0.0.1:3128/"

# This is also a handy place to tweak where Docker's temporary files go.#export TMPDIR="/mnt/bigdrive/docker-tmp"

Change the default Docker network address

Page 33: Vagrant move over, here is Docker
Page 34: Vagrant move over, here is Docker
Page 35: Vagrant move over, here is Docker

*Mounting volumes absolute FROM GUESTdocker run -v /c/Users:containerPath

* hosts file need to be set with 192.168.59.103

Page 36: Vagrant move over, here is Docker

Lightweight Tiny Core Linux made for Docker containers. Runs completely from RAM, weighs ~27MB, boots in ~5s

Page 37: Vagrant move over, here is Docker

Remember:Keep your docker

Images single responsibility

http://blog.nickbelhomme.com | https://joind.in/12295