Slide 1

Slide 1 text

Multi container applications with Docker Compose ContainerDay 2019 – Bologna, Italy

Slide 2

Slide 2 text

Who am I? 2 Paolo Ferretti Developer Advocate @MailUpGroup Twitter: @paoferretti

Slide 3

Slide 3 text

What is Docker Compose? 3 Docker Compose is a tool for defining and running multi-container Docker applications.

Slide 4

Slide 4 text

Docker Compose background First Fig release End 2013 Fig release 1.0.0 October 2014 Docker Compose release 1.24 Today Fig joins Docker July 2014 Fig renames to Docker Compose November 2014 4

Slide 5

Slide 5 text

5 ~ 17.700 GitHub stars ~ 3.000 OSS libraries and projects depends on > 1.400.000 Downloads on PyPi last month

Slide 6

Slide 6 text

Docker Compose 6 Simple YAML file to configure your application’s services. With a single command, you create and start all the services from your configuration. Docker Compose works in all environments: - production - staging - development - testing - CI workflows HOW? WHERE?

Slide 7

Slide 7 text

Multiple isolated environments on a single host Preserve volume data when containers are created Variables and composition between environments Only recreate containers that have changed 7 Docker Compose main features

Slide 8

Slide 8 text

Version: (mandatory): the first line at the root of the file Services: definitions for the different application services Volumes: volumes to create for our services Networks: networks to create for our services 8 version: "3" services: web: … database: … networks: … volumes: … Docker Compose file structure

Slide 9

Slide 9 text

version: "3" services: marty: image: container_day_marty:latest ports: - 8080:8080 A first version of our Docker Compose file 9 $ docker-compose -f docker-compose-simple.yml up

Slide 10

Slide 10 text

version: "3" services: marty: image: container_day_marty:latest ports: - 8080:8080 A second version of our Docker Compose file 10 emmet: image: container_day_emmet:latest ports: - 8081:8080

Slide 11

Slide 11 text

11 version: "3" services: lorraine: … depends_on: [database] database: image: postgres:12.0-alpine volumes: - ./postgres:/docker-entrypoint-initdb.d An example with a database

Slide 12

Slide 12 text

12 version: "3" services: lorraine: image: ...:latest ports: - 8080:8080 depends_on: [database] Let’s compose with Docker Compose version: "3" services: database: image: postgres:12.0-alpine volumes: - ./postgres:/docker-entrypoint-initdb.d docker-compose-app.yml docker-compose-services.yml $ docker-compose -f docker-compose-app.yml -f docker-compose-services.yml up

Slide 13

Slide 13 text

13 version: "3" services: database: ports: - 5432:5432 Compose for local and containerized execution version: "3" services: database: image: postgres:12.0-alpine volumes: - ... docker-compose-services.yml $ docker-compose -f docker-compose-services.yml -f docker-compose-services-local.yml up docker-compose-services-local.yml

Slide 14

Slide 14 text

$ docker-compose \ -f docker-compose-app.yml \ -f docker-compose-services.yml \ run lorraine $ docker-compose \ -f docker-compose-app.yml \ -f docker-compose-services.yml \ down --rmi local --volumes --remove-orphans Execute, exit and clean up 14

Slide 15

Slide 15 text

Using the environment variable COMPOSE_PROJECT_NAME We can run the same compose stack multiple times on the same machine, without conflicts. Multiple executions 15

Slide 16

Slide 16 text

Thanks! @paoferretti [email protected] https://joind.in/talk/4d86a https://github.com/pferretti/container_day_2019

Slide 17

Slide 17 text

Credits ◂ Presentation template by Slidesgo ◂ Icons by Flaticon ◂ Images & infographics by Freepik ◂ Photos created by Freepik - Freepik.com