# Compose

## Problem

* Developers face challenges with multi-container Docker applications, including complex configuration, dependency management, and maintaining consistent environments.
* Networking, resource allocation, data persistence, logging, and monitoring add to the difficulty.
* Security concerns and troubleshooting issues further complicate the process, requiring effective tools and practices for efficient management.

## Solution

* Docker Compose solves the problem of managing multi-container Docker applications by providing a simple way to define, configure, and run all the containers needed for an application using a single YAML file.
* This approach helps developers to easily set up, share, and maintain consistent development, testing, and production environments, ensuring that complex applications can be deployed with all their dependencies and services properly configured and orchestrated.

## About

* Docker Compose is an essential tool for defining and running multi-container Docker applications.
* Docker Compose simplifies the Docker experience, making it easier for developers to create, manage, and deploy applications by using YAML files to configure application services.
* Benefits of Docker Compose are,
  * Lets you define multi-container applications in a single YAML file.
  * Ensures consistent environments across development, testing, and production.
  * Manages the startup and linking of multiple containers effortlessly.
  * Streamlines development workflows and reduces setup time.
  * Ensures that each service runs in its own container, avoiding conflicts.
* Docker containers created in a docker-compose file are created in same network by default, unless specified explicitly.

### Restart policy

* Whenever a container crashed due to some reason, one can specify whether the container should start again or not.
*   Following table summarizes the available restart policies.

    | Policy name    | Description                                                                                          |
    | -------------- | ---------------------------------------------------------------------------------------------------- |
    | "no"           | Do not restart if the container crashes or stops                                                     |
    | always         | Always attempt to restart if the container stops, typically used for a web server.                   |
    | on-failure     | Only restart if the container stops with an error code, typically used for a worker like application |
    | unless-stopped | Always restart unless stopped                                                                        |

## References

* [Docker Compose Guide](https://docs.docker.com/guides/docker-compose/)
* [Compose Reference](https://docs.docker.com/reference/compose-file/)
* [Docker Compose Manual](https://docs.docker.com/compose/)
