DockerCon EU 2015: Continuous Integration with Jenkins, Docker and Compose
Docker Compose by Aanand Prasad
-
Upload
docker-inc -
Category
Technology
-
view
27.142 -
download
3
description
Transcript of Docker Compose by Aanand Prasad
![Page 1: Docker Compose by Aanand Prasad](https://reader033.fdocuments.in/reader033/viewer/2022042607/559b61af1a28ab025f8b4774/html5/thumbnails/1.jpg)
Docker Compose
![Page 2: Docker Compose by Aanand Prasad](https://reader033.fdocuments.in/reader033/viewer/2022042607/559b61af1a28ab025f8b4774/html5/thumbnails/2.jpg)
Multi-container apps are a hassle.
• Build images from Dockerfiles
• Pull images from the Hub or a private registry
• Configure and create containers
• Start and stop containers
• Stream their logs
![Page 3: Docker Compose by Aanand Prasad](https://reader033.fdocuments.in/reader033/viewer/2022042607/559b61af1a28ab025f8b4774/html5/thumbnails/3.jpg)
Multi-container apps are a hassle.
$ docker pull redis:latest
$ docker build -t web .
$ docker run -d --name=db redis:latest redis-server --appendonly yes
$ docker run -d --name=web --link db:db -p 5000:5000 -v `pwd`:/code web python app.py
![Page 4: Docker Compose by Aanand Prasad](https://reader033.fdocuments.in/reader033/viewer/2022042607/559b61af1a28ab025f8b4774/html5/thumbnails/4.jpg)
Multi-container apps are a hassle.
$ docker pull ...$ docker pull ...$ docker build ...$ docker build ...
$ docker run ...$ docker run ...$ docker run ...$ docker run ...
![Page 5: Docker Compose by Aanand Prasad](https://reader033.fdocuments.in/reader033/viewer/2022042607/559b61af1a28ab025f8b4774/html5/thumbnails/5.jpg)
Docker Compose:Get an app running in one command.
$ docker up
Text file
![Page 6: Docker Compose by Aanand Prasad](https://reader033.fdocuments.in/reader033/viewer/2022042607/559b61af1a28ab025f8b4774/html5/thumbnails/6.jpg)
Native Docker API
The same API used by other Docker commands.
The same API used by other Docker tools.
The same API exposed by Docker Swarm.
Multi-container apps on multi-host clusters.
![Page 7: Docker Compose by Aanand Prasad](https://reader033.fdocuments.in/reader033/viewer/2022042607/559b61af1a28ab025f8b4774/html5/thumbnails/7.jpg)
Built into the Docker client
• New command: docker up• Enhanced commands: docker build, pull, run, start, stop, kill, rm...
![Page 8: Docker Compose by Aanand Prasad](https://reader033.fdocuments.in/reader033/viewer/2022042607/559b61af1a28ab025f8b4774/html5/thumbnails/8.jpg)
app.py
from flask import Flaskfrom redis import Redis
app = Flask(__name__)redis = Redis(host="redis", 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 9: Docker Compose by Aanand Prasad](https://reader033.fdocuments.in/reader033/viewer/2022042607/559b61af1a28ab025f8b4774/html5/thumbnails/9.jpg)
requirements.txt
flaskredis
![Page 10: Docker Compose by Aanand Prasad](https://reader033.fdocuments.in/reader033/viewer/2022042607/559b61af1a28ab025f8b4774/html5/thumbnails/10.jpg)
Dockerfile
FROM python:2.7ADD . /codeWORKDIR /codeRUN pip install -r requirements.txt
![Page 11: Docker Compose by Aanand Prasad](https://reader033.fdocuments.in/reader033/viewer/2022042607/559b61af1a28ab025f8b4774/html5/thumbnails/11.jpg)
group.ymlname: counter
containers: web: build: . command: python app.py ports: - "5000:5000" volumes: - .:/code links: - redis redis: image: redis:latest
![Page 12: Docker Compose by Aanand Prasad](https://reader033.fdocuments.in/reader033/viewer/2022042607/559b61af1a28ab025f8b4774/html5/thumbnails/12.jpg)
Demo
![Page 13: Docker Compose by Aanand Prasad](https://reader033.fdocuments.in/reader033/viewer/2022042607/559b61af1a28ab025f8b4774/html5/thumbnails/13.jpg)
Enhanced syntax which refers to group.yml
Same as before: docker rm mycontainer
New form:docker rm :web
Equivalent to: docker rm [name of the web container] (if the web container exists)
![Page 14: Docker Compose by Aanand Prasad](https://reader033.fdocuments.in/reader033/viewer/2022042607/559b61af1a28ab025f8b4774/html5/thumbnails/14.jpg)
Enhanced syntax which refers to group.yml
New form:docker rm :
Equivalent to: docker rm [all containers defined in group.yml]
![Page 15: Docker Compose by Aanand Prasad](https://reader033.fdocuments.in/reader033/viewer/2022042607/559b61af1a28ab025f8b4774/html5/thumbnails/15.jpg)
Enhanced syntax which refers to group.yml
List all running containers defined in group.yml:
docker ps :
Manually rebuild the web image:
docker build :web
Manually re-pull the redis image:
docker pull :redis
![Page 16: Docker Compose by Aanand Prasad](https://reader033.fdocuments.in/reader033/viewer/2022042607/559b61af1a28ab025f8b4774/html5/thumbnails/16.jpg)
Demo
![Page 17: Docker Compose by Aanand Prasad](https://reader033.fdocuments.in/reader033/viewer/2022042607/559b61af1a28ab025f8b4774/html5/thumbnails/17.jpg)
Open design questions
![Page 18: Docker Compose by Aanand Prasad](https://reader033.fdocuments.in/reader033/viewer/2022042607/559b61af1a28ab025f8b4774/html5/thumbnails/18.jpg)
Should the app name be included in group.yml?
name: counter
containers: ...
![Page 19: Docker Compose by Aanand Prasad](https://reader033.fdocuments.in/reader033/viewer/2022042607/559b61af1a28ab025f8b4774/html5/thumbnails/19.jpg)
Should the app name be included in group.yml?
• Fig users have asked for it(we currently let you override it with --project-name or $FIG_PROJECT_NAME)
• Less portable
• Alternative: generate name and store it in an unversioned file
![Page 20: Docker Compose by Aanand Prasad](https://reader033.fdocuments.in/reader033/viewer/2022042607/559b61af1a28ab025f8b4774/html5/thumbnails/20.jpg)
Should we auto-build?
• Keeps the "one command" promise
• Risk of running an old version of the image
![Page 21: Docker Compose by Aanand Prasad](https://reader033.fdocuments.in/reader033/viewer/2022042607/559b61af1a28ab025f8b4774/html5/thumbnails/21.jpg)
Should we keep Compose separate?
• Avoid inflating the core
• Separate release schedules
• More freedom to experiment
![Page 22: Docker Compose by Aanand Prasad](https://reader033.fdocuments.in/reader033/viewer/2022042607/559b61af1a28ab025f8b4774/html5/thumbnails/22.jpg)
But...
• Initial experience would be better
• Difference between Fig and Docker is unclear to newcomers
• Fig bug reports are often actually Docker bugs
![Page 23: Docker Compose by Aanand Prasad](https://reader033.fdocuments.in/reader033/viewer/2022042607/559b61af1a28ab025f8b4774/html5/thumbnails/23.jpg)
Thank You.