April 08, 2017

Docker Compose

Docker Compose

Particularly with multi-tiered applications, your Dockerfile and runtime commands get increasingly complex. Docker Compose is a tool to streamline the definition and instantiation of multi-tier, multi-container Docker applications. Compose requires a single configuration file and a single command to organize and spin up the application tier.

Docker Compose simplifies the containerization of a multi-tier, multi-container application, which can be stitched together using the docker-compose.yml configuration file and the docker-compose command to provide a single application service.

The Compose file provides a way to document and configure all of the application’s service dependencies (databases, queues, caches, web service APIs, etc.)
  • Docker Compose defines and runs complex services:
    • define single containers via Dockerfile
    • describe a multi-container application via single configuration file (docker-compose.yml)
    • manage application stack via a single binary (docker-compose up)
    • link services through Service Discovery
  • The Docker Compose configuration file specifies the services, networks, and volumes to run:
    • services - the equivalent of passing command-line parameters to docker run
    • networks - analogous to definitions from docker network create
    • volumes - analogous to  definitions from docker volume create
  • The Compose configuration file is a YAML declarative file format:
    • YAML Ain’t Markup Language (YAML)
    • YAML philosophy is that "When data is easy to view and understand, programming becomes a simpler task"
    • human-friendly and compatible with modern programming languages for common tasks
    • Minimal structure for maximum data:
      • indentation may be used for structure
      • colons separate key: value pairs
      • dashes are used to create “bullet” lists
      version: "3"
            services:
                web:
                     build: .
                     volumes:
                         - web-data:/var/www/data
                redis:
                     image: redis:alpine
                     ports:
                          - "6379"
                     networks:
                          - default
  • Docker Compose file, docker-compose.yml:
    • describes the services, networks, and volumes of the application stack
    • document and configure the application’s service dependencies (databases, queues, caches, web service APIs, etc.)
    • Use one or more -f flags to call the Compose configuration file. Without the -f flag, the current directory searched for a docker-compose.yml file.
  • Command examples:
  • docke­r-c­ompose up Launches all containers
    docke­r-c­ompose stop Stop all containers
    docke­r-c­ompose kill Kills all containers
    docke­r-c­ompose exec <se­rvi­ce> <co­mma­nd> Executes a command in the container
  • Enhances security and manageability by moving docker run commands to a YAML file

 

No comments:

Post a Comment