docker compose and panamax - containerdays boston - june 2015

73
Docker Compose and Panamax Jonas Rosland Developer Advocate @jonasrosland [email protected] emccode.github.io June 2015

Upload: jonas-rosland

Post on 06-Aug-2015

378 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Docker Compose and Panamax - ContainerDays Boston - June 2015

Docker Compose and Panamax

Jonas RoslandDeveloper Advocate

@[email protected]

emccode.github.ioJune 2015

Page 2: Docker Compose and Panamax - ContainerDays Boston - June 2015

emccode.github.io

Page 3: Docker Compose and Panamax - ContainerDays Boston - June 2015

Raffle!Follow and tweet

@emccode

Page 4: Docker Compose and Panamax - ContainerDays Boston - June 2015

github.com/emccode/training

Page 5: Docker Compose and Panamax - ContainerDays Boston - June 2015

Different types of management

Developer-focused:- Docker Compose- Panamax

Ops-focused:- Kubernetes- Mesos- Tectonic- Fleet- Docker Swarm

Page 6: Docker Compose and Panamax - ContainerDays Boston - June 2015

First a bit of history

Page 7: Docker Compose and Panamax - ContainerDays Boston - June 2015

Fig

Page 8: Docker Compose and Panamax - ContainerDays Boston - June 2015

Fig

Fast, isolated development environments using Docker.Orchard acquired by Docker July 2014Docker's first acquisition

Page 9: Docker Compose and Panamax - ContainerDays Boston - June 2015

Docker Compose(Fig 2.0)

Page 10: Docker Compose and Panamax - ContainerDays Boston - June 2015

First, let's verify your installs1. boot2docker/docker

2. Docker Compose

Page 11: Docker Compose and Panamax - ContainerDays Boston - June 2015

boot2docker$ boot2docker init$ boot2docker upWaiting for VM and Docker daemon to start................................oooooooooooooooooooooooooooooooooooooooStarted.

Page 12: Docker Compose and Panamax - ContainerDays Boston - June 2015

Docker$ docker versionClient version: 1.6.2Client API version: 1.18Go version (client): go1.4.2Git commit (client): 7c8fca2OS/Arch (client): darwin/amd64Server version: 1.6.2Server API version: 1.18Go version (server): go1.4.2Git commit (server): 7c8fca2OS/Arch (server): linux/amd64

Page 13: Docker Compose and Panamax - ContainerDays Boston - June 2015

Docker Compose$ docker-compose psName Command State Ports------------------------------

Page 14: Docker Compose and Panamax - ContainerDays Boston - June 2015

Optional: Clean up your Docker environmentdocker rm `docker images -q`docker rmi `docker images -q`

Page 15: Docker Compose and Panamax - ContainerDays Boston - June 2015

Docker Compose example (1/3)

Let's define two services:

web- built from Dockerfile- runs the command python app.py inside the image- forwards the exposed port 5000 on the container to port 5000 on the host machine- connects to the Redis service- mounts the current directory inside the container

redis, which uses the public image redis

Page 16: Docker Compose and Panamax - ContainerDays Boston - June 2015

Docker Compose example (2/3)

Dockerfile:FROM python:2.7ADD . /codeWORKDIR /codeRUN pip install -r requirements.txt

Page 17: Docker Compose and Panamax - ContainerDays Boston - June 2015

Docker Compose example (3/3)

docker-compose.yml:web: build: . command: python app.py ports: - "5000:5000" volumes: - .:/code links: - redisredis: image: redis

Page 18: Docker Compose and Panamax - ContainerDays Boston - June 2015

So what are we defining?build - the dir we are building fromcommand - the command we run inside the containerports - the ports we open and map to the hostvolumes - directory we map as a volume and where we mount itlinks - what service we link to (create /etc/hosts lines)

Page 19: Docker Compose and Panamax - ContainerDays Boston - June 2015

Run it!$ docker-compose upCreating lab3dockercomposeandpanamax_redis_1...Pulling image redis:latest...latest: Pulling from redis<snip>Creating lab3dockercomposeandpanamax_web_1...Building web...Step 0 : FROM python:2.72.7: Pulling from python<snip>redis_1 | 1:M 05 Jun 16:20:55.105 * DB loaded from disk: 0.000 secondsredis_1 | 1:M 05 Jun 16:20:55.105 * The server is now ready to accept connections on port 6379web_1 | * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)web_1 | * Restarting with stat

Page 20: Docker Compose and Panamax - ContainerDays Boston - June 2015

Verify that it's running$ docker-compose ps Name Command State Ports--------------------------------------------------------------------------------------------------lab3dockercomposeandpanamax_redis_1 /entrypoint.sh redis-server Up 6379/tcplab3dockercomposeandpanamax_web_1 python app.py Up 0.0.0.0:5000->5000/tcp

Page 21: Docker Compose and Panamax - ContainerDays Boston - June 2015

Wanna verify more stuff?

Page 22: Docker Compose and Panamax - ContainerDays Boston - June 2015

docker ps$ docker psCONTAINER ID IMAGE9f4fe02e2696 lab3dockercomposeandpanamax_web:latestd01f11317166 redis:latest

Page 23: Docker Compose and Panamax - ContainerDays Boston - June 2015

docker exec$ docker exec -ti 9f4fe02e2696 /bin/bashroot@9f4fe02e2696:/code# lsDockerfile app.py docker-compose.yml requirements.txt test

Page 24: Docker Compose and Panamax - ContainerDays Boston - June 2015

docker execroot@9f4fe02e2696:/code# cat /etc/hosts172.17.0.7 9f4fe02e2696127.0.0.1 localhost<snip>172.17.0.5 lab3dockercomposeandpanamax_redis_1 d01f11317166172.17.0.5 redis d01f11317166 lab3dockercomposeandpanamax_redis_1172.17.0.5 redis_1 d01f11317166 lab3dockercomposeandpanamax_redis_1

Page 25: Docker Compose and Panamax - ContainerDays Boston - June 2015

Sooooo, how do we connect to it?$ boot2docker ip192.168.59.103

Page 26: Docker Compose and Panamax - ContainerDays Boston - June 2015
Page 27: Docker Compose and Panamax - ContainerDays Boston - June 2015

Refresh!

Page 28: Docker Compose and Panamax - ContainerDays Boston - June 2015
Page 29: Docker Compose and Panamax - ContainerDays Boston - June 2015

So what have you done?Built a container from scratchRun a web app using Flask in the containerConnect it to RedisStore data in RedisRetrieve the data and present it

Page 30: Docker Compose and Panamax - ContainerDays Boston - June 2015

Pretty cool!

Page 31: Docker Compose and Panamax - ContainerDays Boston - June 2015

What happens if you stop and start it?

Page 32: Docker Compose and Panamax - ContainerDays Boston - June 2015

Was there anything unneccesary in the Dockerfile or docker-

compose.yml?

Page 33: Docker Compose and Panamax - ContainerDays Boston - June 2015

Some more info on Docker Compose

Page 34: Docker Compose and Panamax - ContainerDays Boston - June 2015

External linksLink to containers outside Docker Compose using CONTAINER:ALIASexternal_links: - redis_1 - project_db_1:mysql - project_db_1:postgresql

Page 35: Docker Compose and Panamax - ContainerDays Boston - June 2015

PortsUsing the HOST:CONTAINER format, don't use ports lower than 60, because YAML will parse numbers in the format xx:yy as sexagesimal (base 60). For this reason, we recommend always adding port mappings as strings.

ports: - "3000" - "8000:8000" - "49100:22" - "127.0.0.1:8001:8001"

Page 36: Docker Compose and Panamax - ContainerDays Boston - June 2015

What about scaling?

Page 37: Docker Compose and Panamax - ContainerDays Boston - June 2015

Let's change our docker-compose.ymlweb: build: . command: python app.py ports: - "5000" links: - redisredis: image: redis

Page 38: Docker Compose and Panamax - ContainerDays Boston - June 2015

Re-run docker-compose up$ docker-compose up<snip>$ docker-compose ps Name Command State Ports---------------------------------------------------------------------------------------------------lab3dockercomposeandpanamax_redis_1 /entrypoint.sh redis-server Up 6379/tcplab3dockercomposeandpanamax_web_1 python app.py Up 0.0.0.0:32770->5000/tcp

See the port number?

Page 39: Docker Compose and Panamax - ContainerDays Boston - June 2015
Page 40: Docker Compose and Panamax - ContainerDays Boston - June 2015

Scale it!$ docker-compose scale web=3Creating lab3dockercomposeandpanamax_web_2...Creating lab3dockercomposeandpanamax_web_3...Starting lab3dockercomposeandpanamax_web_2...Starting lab3dockercomposeandpanamax_web_3...

Page 41: Docker Compose and Panamax - ContainerDays Boston - June 2015

Check the ports$ docker-compose ps Name Command State Ports---------------------------------------------------------------------------------------------------lab3dockercomposeandpanamax_redis_1 /entrypoint.sh redis-server Up 6379/tcplab3dockercomposeandpanamax_web_1 python app.py Up 0.0.0.0:32770->5000/tcplab3dockercomposeandpanamax_web_2 python app.py Up 0.0.0.0:32771->5000/tcplab3dockercomposeandpanamax_web_3 python app.py Up 0.0.0.0:32772->5000/tcp

Page 42: Docker Compose and Panamax - ContainerDays Boston - June 2015
Page 43: Docker Compose and Panamax - ContainerDays Boston - June 2015
Page 44: Docker Compose and Panamax - ContainerDays Boston - June 2015

So what have you done?Scaled a web appConnected all web instances to a shared Redis DBStored persistent data in RedisPresented that persistent data using all web instances

Page 45: Docker Compose and Panamax - ContainerDays Boston - June 2015

You are awesome :)

Page 46: Docker Compose and Panamax - ContainerDays Boston - June 2015

One more thing...

Page 47: Docker Compose and Panamax - ContainerDays Boston - June 2015

Docker Compose Extends!

Page 48: Docker Compose and Panamax - ContainerDays Boston - June 2015

ExtendsEnables sharing of common configsLets you reuse commonly-defined services

Page 49: Docker Compose and Panamax - ContainerDays Boston - June 2015

So how do we do this?

Page 50: Docker Compose and Panamax - ContainerDays Boston - June 2015

Lets take our example app again

Page 51: Docker Compose and Panamax - ContainerDays Boston - June 2015

app.pyfrom flask import Flaskfrom redis import Redisimport os

app = Flask(__name__)redis = Redis(host=os.environ['REDIS_HOST'], port=6379)

@app.route('/')def hello(): redis.incr('hits') return 'Hello World! I have been seen %s times.\n' % redis.get('hits')

if __name__ == "__main__": app.run(host="0.0.0.0", debug=True)

Page 52: Docker Compose and Panamax - ContainerDays Boston - June 2015

DockerfileFROM python:2.7ADD . /codeWORKDIR /codeRUN pip install -r requirements.txtCMD python app.py

Page 53: Docker Compose and Panamax - ContainerDays Boston - June 2015

common.ymlweb: build: . ports: - "5000:5000"

Page 54: Docker Compose and Panamax - ContainerDays Boston - June 2015

docker-compose.ymlweb: extends: file: common.yml service: web volumes: - .:/code links: - redis environment: - REDIS_HOST=redisredis: image: redis

Page 55: Docker Compose and Panamax - ContainerDays Boston - June 2015

docker-compose up

Page 56: Docker Compose and Panamax - ContainerDays Boston - June 2015

Try changing app.py to see what happens :)

Page 57: Docker Compose and Panamax - ContainerDays Boston - June 2015

production.ymlweb: extends: file: common.yml service: web environment: - REDIS_HOST=redis-production.example.com

Page 58: Docker Compose and Panamax - ContainerDays Boston - June 2015

docker-compose -f production.yml up

Page 59: Docker Compose and Panamax - ContainerDays Boston - June 2015

Alright, time for Panamax

Page 60: Docker Compose and Panamax - ContainerDays Boston - June 2015

Panamax

An open-source project that makes deploying complex containerized apps as easy as Drag-and-DropCreated by CenturyLink LabsReleased in August 2014

Page 61: Docker Compose and Panamax - ContainerDays Boston - June 2015
Page 62: Docker Compose and Panamax - ContainerDays Boston - June 2015

Search for images

Page 63: Docker Compose and Panamax - ContainerDays Boston - June 2015

Run images in "apps"

Page 64: Docker Compose and Panamax - ContainerDays Boston - June 2015
Page 65: Docker Compose and Panamax - ContainerDays Boston - June 2015

Manage and add more images to an app

Page 66: Docker Compose and Panamax - ContainerDays Boston - June 2015

Expose ports

Page 67: Docker Compose and Panamax - ContainerDays Boston - June 2015

Link containers together

Page 68: Docker Compose and Panamax - ContainerDays Boston - June 2015

Verify you've got Panamax installed$ panamax init

Page 69: Docker Compose and Panamax - ContainerDays Boston - June 2015

Port forwarding your Panamax instanceVBoxManage controlvm panamax-vm natpf1 rule1,tcp,,8080,,80

Page 70: Docker Compose and Panamax - ContainerDays Boston - June 2015

Demotime!!

Page 71: Docker Compose and Panamax - ContainerDays Boston - June 2015

Hope you all enjoyed this workshop :)

Page 72: Docker Compose and Panamax - ContainerDays Boston - June 2015

ContactJonas Rosland

Developer Advocate

@[email protected]

emccode.github.io

Page 73: Docker Compose and Panamax - ContainerDays Boston - June 2015

Fin