0% found this document useful (0 votes)
41 views22 pages

Module 10 - Docker Compose

The document discusses Docker Compose, a tool that allows users to define and run multi-container Docker applications. It covers what Docker Compose is, its features, installation process, use of YAML files to define applications, and common commands. The document also provides an example of a simple Docker Compose YAML file and agenda for labs that will dive deeper into using Docker Compose.

Uploaded by

Ishita Jindal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views22 pages

Module 10 - Docker Compose

The document discusses Docker Compose, a tool that allows users to define and run multi-container Docker applications. It covers what Docker Compose is, its features, installation process, use of YAML files to define applications, and common commands. The document also provides an example of a simple Docker Compose YAML file and agenda for labs that will dive deeper into using Docker Compose.

Uploaded by

Ishita Jindal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Module 10: Docker Compose

Docker Workshop

© Copyright SELA Software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com | Leon Jalfon - Blog: http://blogs.microsoft.co.il/leonj
Agenda
What is docker compose?
Features
Installation
YML File
Commands
Lab 10: Simple Docker Compose
Dive into the YML File
Lab 11: Docker Compose
© Copyright SELA Software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com | Leon Jalfon - Blog: http://blogs.microsoft.co.il/leonj
What is docker compose?

Docker Compose is a tool for defining and


running complex applications with Docker.

Define a multi-container application in a single


file

Spin your application up in a single command

© Copyright SELA Software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com | Leon Jalfon - Blog: http://blogs.microsoft.co.il/leonj
Features
Multiple isolated environments on a single host

Preserve volume data when containers are created

Only recreate containers that have changed

Variables and moving a composition between environments

Multiple compose files

© Copyright SELA Software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com | Leon Jalfon - Blog: http://blogs.microsoft.co.il/leonj
Installation
Windows / Mac - Docker Compose is included 

Linux:
sudo curl -L
https://github.com/docker/compose/releases/download/1.21.2/docker-
compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose

Test the installation


docker-compose --version

© Copyright SELA Software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com | Leon Jalfon - Blog: http://blogs.microsoft.co.il/leonj
Before Docker Compose

$ docker run -d -it --name redis redis


$ docker run -d -it --name postgres linhmtran168/postgres
$ docker run -d -it --name web \ -v
~/Dev/gitlab.com/linhmtran168/test-project:/var/www/html \ --link
postgres:db --link redis:redis linhmtran168/php-web
$ docker run -d -it -p 80:80 --name nginx \ --link web:web --volumes-
from web linhmtran168/php-nginx
$ docker run -d -it --name node --link web:web \ --volumes-from web
linhmtran168/gulp-bower

© Copyright SELA Software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com | Leon Jalfon - Blog: http://blogs.microsoft.co.il/leonj
After Docker Compose
web:
build: .
links:
- redis:redis
- postgres:db
volumes:
- .:/var/www/html

nginx:
build: ../docker-php-nginx
ports:
- "80:80"
links:
- web:web
volumes_from:
- web

© Copyright SELA Software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com | Leon Jalfon - Blog: http://blogs.microsoft.co.il/leonj
YML File
Version
Services
Build
Image
Environment
Ports
Volumes

Volumes

Networks

© Copyright SELA Software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com | Leon Jalfon - Blog: http://blogs.microsoft.co.il/leonj
Simple YML File
version: '3'

services:
jenkins:
image: jenkins/jenkins:lts
ports:
- “8080:8080”
- “50000:50000”

artifactory:
image: docker.bintray.io/jfrog/artifactory-oss:latest
ports:
- 8081:8081

© Copyright SELA Software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com | Leon Jalfon - Blog: http://blogs.microsoft.co.il/leonj
Commands
Create and start all the containers listed in the “docker-compose.yml”

$ docker-compose up -d

List all the containers belong to the compose environment instance:

$ docker-compose ps

Sets the number of containers:

$ docker-compose scale web=3

© Copyright SELA Software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com | Leon Jalfon - Blog: http://blogs.microsoft.co.il/leonj
Commands
build Build or rebuild services
help Get help on a command
kill Kill containers
logs View output from containers
port Print the public port for a port binding
ps List containers
pull Pulls service images
rm Remove stopped containers
run Run a one-off command
scale Set number of containers for a service
start Start services
stop Stop services
restart Restart services
up Create and start containers

© Copyright SELA Software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com | Leon Jalfon - Blog: http://blogs.microsoft.co.il/leonj
Docker Compose

Demo

© Copyright SELA Software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com | DevOps Course | Leon Jalfon – [email protected]
Lab 10: Simple Docker Compose

Lab
https://gitlab.com/docker-workshop/Lab-11

© Copyright SELA Software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com | Leon Jalfon - Blog: http://blogs.microsoft.co.il/leonj
Dive into the YML File
version: '3'
Image / Build
services:
jenkins:
image: jenkins/jenkins:lts image: jenkins/jenkins:lts
ports:
build: ./dir - “8080:8080”
- “50000:50000”
myapp:
build: ./dir

© Copyright SELA Software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com | Leon Jalfon - Blog: http://blogs.microsoft.co.il/leonj
Dive into the YML File
Depends_on version: '3'

services:
web: web:
build: .
build: . depends_on:
depends_on: - db
- redis
- db
- redis

© Copyright SELA Software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com | Leon Jalfon - Blog: http://blogs.microsoft.co.il/leonj
Dive into the YML File
Restart version: '3'

services:
jenkins:
restart: "no" image: jenkins/jenkins:lts
restart: always ports:
- “8080:8080”
restart: on-failure - “50000:50000”
restart: unless-stopped restart: alwayes

© Copyright SELA Software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com | Leon Jalfon - Blog: http://blogs.microsoft.co.il/leonj
Dive into the YML File
Environment version: '3'

services:
jenkins:
MYSQL_USER: wordpress image: jenkins/jenkins:lts
MYSQL_PASSWORD: wordpress ports:
- “8080:8080”
- “50000:50000”
restart: always
Environment File environment:
MYSQL_USER: wordpress
env_file: .env env_file: .env

© Copyright SELA Software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com | Leon Jalfon - Blog: http://blogs.microsoft.co.il/leonj
version: '3'
Dive into the YML File services:
jenkins:
Networks image: jenkins/jenkins:lts
ports:
- “8080:8080”
web: - “50000:50000”
networks: restart: always
environment:
- sela
MYSQL_USER: wordpress
networks:
- sela

networks:
sela: networks:
sela:
other: other:

© Copyright SELA Software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com | Leon Jalfon - Blog: http://blogs.microsoft.co.il/leonj
version: '3'

Dive into the YML File services:


jenkins:
image: jenkins/jenkins:lts
ports:
Volumes - “8080:8080”
- “50000:50000”
restart: always
volumes: environment:
MYSQL_USER: wordpress
- "dbdata:/var/lib/postgresql/data" networks:
- sela
volumes:
- dbdata:/var/lib/postgresql/data

volumes : networks:
sela:
dbdata: other:

Volumes:
dbdata:
© Copyright SELA Software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com | Leon Jalfon - Blog: http://blogs.microsoft.co.il/leonj
Docker Compose

Demo

© Copyright SELA Software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com | DevOps Course | Leon Jalfon – [email protected]
Lab 11: Docker Compose

Lab
https://gitlab.com/docker-workshop/Lab-12

© Copyright SELA Software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com | Leon Jalfon - Blog: http://blogs.microsoft.co.il/leonj
Questions

© Copyright SELA Software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com | Leon Jalfon - Blog: http://blogs.microsoft.co.il/leonj

You might also like