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

Multi container applications with Docker Compose

Multi container applications with Docker Compose

Docker è ottimo per applicazioni singole, ma è sicuramente meglio per applicazioni multi-container! In questo talk vedremo come possiamo usare Docker Compose per riprodurre fedelmente sulla nostra macchina locale i nostri stack di produzione. Analizzeremo anche il caso di una applicazione sviluppata da noi e testabile in diversi ambienti grazie alla componibilità degli stack di Docker Compose.

Paolo Ferretti

November 08, 2019
Tweet

More Decks by Paolo Ferretti

Other Decks in Programming

Transcript

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

    for defining and running multi-container Docker applications.
  2. 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
  3. 5 ~ 17.700 GitHub stars ~ 3.000 OSS libraries and

    projects depends on > 1.400.000 Downloads on PyPi last month
  4. 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?
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. $ 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
  13. 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
  14. Credits ◂ Presentation template by Slidesgo ◂ Icons by Flaticon

    ◂ Images & infographics by Freepik ◂ Photos created by Freepik - Freepik.com