Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Docker Compose and
Panamax
Jonas Rosland
Developer Advocate
@jonasrosland
jonas.rosland@emc.com
emccode.github.io
June 2015
emccode.github.io
Raffle!
Follow and tweet
@emccode
github.com/emccode/training
Different types of management
Developer-focused:
- Docker Compose
- Panamax
Ops-focused:
- Kubernetes
- Mesos
- Tectonic
-...
First a bit of history
Fig
Fig
Fast, isolated development environments using Docker.
Orchard acquired by Docker July 2014
Docker's first acquisition
Docker Compose
(Fig 2.0)
First, let's verify your installs
1. boot2docker/docker
2. Docker Compose
boot2docker
$ boot2docker init
$ boot2docker up
Waiting for VM and Docker daemon to start...
................................
Docker
$ docker version
Client version: 1.6.2
Client API version: 1.18
Go version (client): go1.4.2
Git commit (client): 7...
Docker Compose
$ docker-compose ps
Name Command State Ports
------------------------------
Optional: Clean up your Docker
environment
docker rm `docker images -q`
docker rmi `docker images -q`
Docker Compose example (1/3)
Let's define two services:
web
- built from Dockerfile
- runs the command python app.py inside ...
Docker Compose example (2/3)
Dockerfile:
FROM python:2.7
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
Docker Compose example (3/3)
docker-compose.yml:
web:
build: .
command: python app.py
ports:
- "5000:5000"
volumes:
- .:/c...
So what are we defining?
build - the dir we are building from
command - the command we run inside the container
ports - th...
Run it!
$ docker-compose up
Creating lab3dockercomposeandpanamax_redis_1...
Pulling image redis:latest...
latest: Pulling ...
Verify that it's running
$ docker-compose ps
Name Command State Ports
----------------------------------------------------...
Wanna verify more
stuff?
docker ps
$ docker ps
CONTAINER ID IMAGE
9f4fe02e2696 lab3dockercomposeandpanamax_web:latest
d01f11317166 redis:latest
docker exec
$ docker exec -ti 9f4fe02e2696 /bin/bash
root@9f4fe02e2696:/code# ls
Dockerfile app.py docker-compose.yml requ...
docker exec
root@9f4fe02e2696:/code# cat /etc/hosts
172.17.0.7 9f4fe02e2696
127.0.0.1 localhost
<snip>
172.17.0.5 lab3dock...
Sooooo, how do we connect to it?
$ boot2docker ip
192.168.59.103
Refresh!
So what have you done?
Built a container from scratch
Run a web app using Flask in the container
Connect it to Redis
Store...
Pretty cool!
What happens if you
stop and start it?
Was there anything unneccesary
in the Dockerfile or docker-
compose.yml?
Some more info on
Docker Compose
External links
Link to containers outside Docker Compose using
CONTAINER:ALIAS
external_links:
- redis_1
- project_db_1:my...
Ports
Using the HOST:CONTAINER format, don't use ports lower
than 60, because YAML will parse numbers in the format xx:yy
...
What about scaling?
Let's change our docker-
compose.yml
web:
build: .
command: python app.py
ports:
- "5000"
links:
- redis
redis:
image: red...
Re-run docker-compose up
$ docker-compose up
<snip>
$ docker-compose ps
Name Command State Ports
-------------------------...
Scale it!
$ docker-compose scale web=3
Creating lab3dockercomposeandpanamax_web_2...
Creating lab3dockercomposeandpanamax_...
Check the ports
$ docker-compose ps
Name Command State Ports
-------------------------------------------------------------...
So what have you done?
Scaled a web app
Connected all web instances to a shared Redis DB
Stored persistent data in Redis
P...
You are awesome :)
One more thing...
Docker Compose
Extends!
Extends
Enables sharing of common configs
Lets you reuse commonly-defined services
So how do we do
this?
Lets take our example
app again
app.py
from flask import Flask
from redis import Redis
import os
app = Flask(__name__)
redis = Redis(host=os.environ['REDI...
Dockerfile
FROM python:2.7
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
CMD python app.py
common.yml
web:
build: .
ports:
- "5000:5000"
docker-compose.yml
web:
extends:
file: common.yml
service: web
volumes:
- .:/code
links:
- redis
environment:
- REDIS_HOST...
docker-compose up
Try changing app.py to see what
happens :)
production.yml
web:
extends:
file: common.yml
service: web
environment:
- REDIS_HOST=redis-production.example.com
docker-compose -f production.yml up
Alright, time for
Panamax
Panamax
An open-source project that makes deploying complex
containerized apps as easy as Drag-and-Drop
Created by Century...
Search for images
Run images in "apps"
Manage and add more images to an app
Expose ports
Link containers together
Verify you've got Panamax
installed
$ panamax init
Port forwarding your Panamax
instance
VBoxManage controlvm panamax-vm natpf1 rule1,tcp,,8080,,80
Demotime!!
Hope you all enjoyed
this workshop :)
Contact
Jonas Rosland
Developer Advocate
@jonasrosland
jonas.rosland@emc.com
emccode.github.io
Fin
Docker Compose and Panamax - ContainerDays Boston - June 2015
Docker Compose and Panamax - ContainerDays Boston - June 2015
Docker Compose and Panamax - ContainerDays Boston - June 2015
Docker Compose and Panamax - ContainerDays Boston - June 2015
Docker Compose and Panamax - ContainerDays Boston - June 2015
Docker Compose and Panamax - ContainerDays Boston - June 2015
Docker Compose and Panamax - ContainerDays Boston - June 2015
Upcoming SlideShare
Loading in …5
×

Docker Compose and Panamax - ContainerDays Boston - June 2015

1,417 views

Published on

Workshop held at ContainerDays Boston around Docker Compose and Panamax

Published in: Technology
  • Be the first to comment

Docker Compose and Panamax - ContainerDays Boston - June 2015

  1. 1. Docker Compose and Panamax Jonas Rosland Developer Advocate @jonasrosland jonas.rosland@emc.com emccode.github.io June 2015
  2. 2. emccode.github.io
  3. 3. Raffle! Follow and tweet @emccode
  4. 4. github.com/emccode/training
  5. 5. Different types of management Developer-focused: - Docker Compose - Panamax Ops-focused: - Kubernetes - Mesos - Tectonic - Fleet - Docker Swarm
  6. 6. First a bit of history
  7. 7. Fig
  8. 8. Fig Fast, isolated development environments using Docker. Orchard acquired by Docker July 2014 Docker's first acquisition
  9. 9. Docker Compose (Fig 2.0)
  10. 10. First, let's verify your installs 1. boot2docker/docker 2. Docker Compose
  11. 11. boot2docker $ boot2docker init $ boot2docker up Waiting for VM and Docker daemon to start... .............................ooooooooooooooooooooooooooooooooooooooo Started.
  12. 12. Docker $ docker version Client version: 1.6.2 Client API version: 1.18 Go version (client): go1.4.2 Git commit (client): 7c8fca2 OS/Arch (client): darwin/amd64 Server version: 1.6.2 Server API version: 1.18 Go version (server): go1.4.2 Git commit (server): 7c8fca2 OS/Arch (server): linux/amd64
  13. 13. Docker Compose $ docker-compose ps Name Command State Ports ------------------------------
  14. 14. Optional: Clean up your Docker environment docker rm `docker images -q` docker rmi `docker images -q`
  15. 15. 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
  16. 16. Docker Compose example (2/3) Dockerfile: FROM python:2.7 ADD . /code WORKDIR /code RUN pip install -r requirements.txt
  17. 17. Docker Compose example (3/3) docker-compose.yml: web: build: . command: python app.py ports: - "5000:5000" volumes: - .:/code links: - redis redis: image: redis
  18. 18. So what are we defining? build - the dir we are building from command - the command we run inside the container ports - the ports we open and map to the host volumes - directory we map as a volume and where we mount it links - what service we link to (create /etc/hosts lines)
  19. 19. Run it! $ docker-compose up Creating lab3dockercomposeandpanamax_redis_1... Pulling image redis:latest... latest: Pulling from redis <snip> Creating lab3dockercomposeandpanamax_web_1... Building web... Step 0 : FROM python:2.7 2.7: Pulling from python <snip> redis_1 | 1:M 05 Jun 16:20:55.105 * DB loaded from disk: 0.000 seconds redis_1 | 1:M 05 Jun 16:20:55.105 * The server is now ready to accept connections on port 6379 web_1 | * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit) web_1 | * Restarting with stat
  20. 20. Verify that it's running $ docker-compose ps Name Command State Ports -------------------------------------------------------------------------------------------------- lab3dockercomposeandpanamax_redis_1 /entrypoint.sh redis-server Up 6379/tcp lab3dockercomposeandpanamax_web_1 python app.py Up 0.0.0.0:5000->5000/tcp
  21. 21. Wanna verify more stuff?
  22. 22. docker ps $ docker ps CONTAINER ID IMAGE 9f4fe02e2696 lab3dockercomposeandpanamax_web:latest d01f11317166 redis:latest
  23. 23. docker exec $ docker exec -ti 9f4fe02e2696 /bin/bash root@9f4fe02e2696:/code# ls Dockerfile app.py docker-compose.yml requirements.txt test
  24. 24. docker exec root@9f4fe02e2696:/code# cat /etc/hosts 172.17.0.7 9f4fe02e2696 127.0.0.1 localhost <snip> 172.17.0.5 lab3dockercomposeandpanamax_redis_1 d01f11317166 172.17.0.5 redis d01f11317166 lab3dockercomposeandpanamax_redis_1 172.17.0.5 redis_1 d01f11317166 lab3dockercomposeandpanamax_redis_1
  25. 25. Sooooo, how do we connect to it? $ boot2docker ip 192.168.59.103
  26. 26. Refresh!
  27. 27. So what have you done? Built a container from scratch Run a web app using Flask in the container Connect it to Redis Store data in Redis Retrieve the data and present it
  28. 28. Pretty cool!
  29. 29. What happens if you stop and start it?
  30. 30. Was there anything unneccesary in the Dockerfile or docker- compose.yml?
  31. 31. Some more info on Docker Compose
  32. 32. External links Link to containers outside Docker Compose using CONTAINER:ALIAS external_links: - redis_1 - project_db_1:mysql - project_db_1:postgresql
  33. 33. Ports Using 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"
  34. 34. What about scaling?
  35. 35. Let's change our docker- compose.yml web: build: . command: python app.py ports: - "5000" links: - redis redis: image: redis
  36. 36. 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/tcp lab3dockercomposeandpanamax_web_1 python app.py Up 0.0.0.0:32770->5000/tcp See the port number?
  37. 37. Scale it! $ docker-compose scale web=3 Creating lab3dockercomposeandpanamax_web_2... Creating lab3dockercomposeandpanamax_web_3... Starting lab3dockercomposeandpanamax_web_2... Starting lab3dockercomposeandpanamax_web_3...
  38. 38. Check the ports $ docker-compose ps Name Command State Ports --------------------------------------------------------------------------------------------------- lab3dockercomposeandpanamax_redis_1 /entrypoint.sh redis-server Up 6379/tcp lab3dockercomposeandpanamax_web_1 python app.py Up 0.0.0.0:32770->5000/tcp lab3dockercomposeandpanamax_web_2 python app.py Up 0.0.0.0:32771->5000/tcp lab3dockercomposeandpanamax_web_3 python app.py Up 0.0.0.0:32772->5000/tcp
  39. 39. So what have you done? Scaled a web app Connected all web instances to a shared Redis DB Stored persistent data in Redis Presented that persistent data using all web instances
  40. 40. You are awesome :)
  41. 41. One more thing...
  42. 42. Docker Compose Extends!
  43. 43. Extends Enables sharing of common configs Lets you reuse commonly-defined services
  44. 44. So how do we do this?
  45. 45. Lets take our example app again
  46. 46. app.py from flask import Flask from redis import Redis import 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)
  47. 47. Dockerfile FROM python:2.7 ADD . /code WORKDIR /code RUN pip install -r requirements.txt CMD python app.py
  48. 48. common.yml web: build: . ports: - "5000:5000"
  49. 49. docker-compose.yml web: extends: file: common.yml service: web volumes: - .:/code links: - redis environment: - REDIS_HOST=redis redis: image: redis
  50. 50. docker-compose up
  51. 51. Try changing app.py to see what happens :)
  52. 52. production.yml web: extends: file: common.yml service: web environment: - REDIS_HOST=redis-production.example.com
  53. 53. docker-compose -f production.yml up
  54. 54. Alright, time for Panamax
  55. 55. Panamax An open-source project that makes deploying complex containerized apps as easy as Drag-and-Drop Created by CenturyLink Labs Released in August 2014
  56. 56. Search for images
  57. 57. Run images in "apps"
  58. 58. Manage and add more images to an app
  59. 59. Expose ports
  60. 60. Link containers together
  61. 61. Verify you've got Panamax installed $ panamax init
  62. 62. Port forwarding your Panamax instance VBoxManage controlvm panamax-vm natpf1 rule1,tcp,,8080,,80
  63. 63. Demotime!!
  64. 64. Hope you all enjoyed this workshop :)
  65. 65. Contact Jonas Rosland Developer Advocate @jonasrosland jonas.rosland@emc.com emccode.github.io
  66. 66. Fin

×