Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Multi-container applications with Docker Compose

Multi-container applications with Docker Compose

Slides for me Techitalia Tuscany talk about multi container applications

Paolo Ferretti

December 07, 2019

More Decks by Paolo Ferretti

Other Decks in Technology


  1. What is Docker Compose? Docker Compose is a tool for

    defining and running multi-container Docker applications.
  2. A better definition Docker Compose is a tool that helps

    you run complex applications. A working software is never an island.
  3. Docker Compose history 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. ~ 17.700 GitHub stars ~ 3.000 OSS libraries and projects

    depends on > 1.400.000 Downloads on Pypi last month
  5. Docker Compose How? Where? 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
  6. Docker Compose main features 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 Internal networking between containers
  7. Docker Compose file structure 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 version:“3” services: web: ... database: ... networks: ... volumes: ...
  8. The anatomy of a multi container application Web App Database

    Redis RabbitMQ Worker docker-compose Volume Volumes
  9. Tear Up/Down $ docker-compose up $ docker-compose down $ docker-compose

    -f docker-compose-custom.yml up $ docker-compose -f docker-compose-custom.yml down Convenient if we use the default file docker-compose.yml
  10. The loop workflow for multi container Docker apps development Code

    your app Write Dockerfile(s) Build your images Define your multi-container architecture Run your multi-container application Test Push and continue developing
  11. The CI case study: Jenkins • Sandboxed environments for tests

    • Possibility to run integration tests • Multiple simultaneous pipeline runs
  12. Multiple executions Using the environment variable COMPOSE_PROJECT_NAME We can run

    the same compose stack multiple times on the same machine, without conflicts.
  13. The CI case study: Jenkins • Sandboxed environments for tests

    • Possibility to run integration tests • Multiple simultaneous pipeline runs • Efficient and effective tear down and cleaning
  14. Execute, exit and clean up $ docker-compose \ -f docker-compose-app.yml

    \ -f docker-compose-services.yml \ run myapp $ docker-compose \ -f docker-compose-app.yml \ -f docker-compose-services.yml \ down --rmi local --volumes --remove-orphans
  15. Let’s compose: a monolithic stack version: "3" services: marty: …

    depends_on: [database] database: image: postgres:12.0-alpine volumes: - ./postgres:/docker-entrypoint-initdb.d
  16. Let’s compose: a splitted stack version: "3" services: marty: image:

    ...:latest ports: - 8080:8080 depends_on: [database] 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
  17. Compose for containerized and local execution version: "3" services: database:

    image: postgres:12.0-alpine volumes: - ... version: "3" services: database: ports: - 5432:5432 docker-compose-services.yml docker-compose-services-local.yml $ docker-compose -f docker-compose-services.yml -f docker-compose-services-local.yml up