|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
- 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:
|docker-compose up||Launches all containers|
|docker-compose stop||Stop all containers|
|docker-compose kill||Kills all containers|
|docker-compose exec <service> <command>||Executes a command in the container|
- Enhances security and manageability by moving docker run commands to a YAML file
|Licensed under a Creative Commons Attribution 4.0 International License.|