# Docker-compose

Docker Compose is a tool that makes it easier to create and run multi-container applications.&#x20;

It automates the process of managing several Docker containers simultaneously, such as a website frontend, API, and database service.

Docker Compose allows you to define your application’s containers as code inside a YAML file you can commit to your source repository.&#x20;

Once you’ve created your file (normally named docker-compose.yml), you can start all your containers (called “services”) with a single Compose command.

<figure><img src="https://921544542-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiRQTWHUNVZ5tIxQJXclF%2Fuploads%2FTRjUzSQq2L3MWg0QHU2q%2Fdocker-compose-button.jpg?alt=media&#x26;token=17b7aa67-7ba6-4397-9349-7125f9f3d8b2" alt=""><figcaption><p>docker-compose</p></figcaption></figure>

Compared with manually starting and linking containers, Compose is quicker, easier, and more repeatable.

Compose automatically creates a Docker network for your project, ensuring your containers can communicate with each other.&#x20;

It also manages your Docker storage volumes, automatically reattaching them after a service is restarted or replaced.

### Why use docker compose?

Most real-world applications have several services with dependency relationships—for example, your app may run in one container, but depend on a database server that’s deployed adjacently in another container.&#x20;

Moreover, services usually need to be configured with storage volumes, environment variables, port bindings, and other settings before they can be deployed.

This improves developer ergonomics, supports reuse of the stack in multiple environments, and helps prevent accidental misconfiguration.

### Docker Compose Workflow

<figure><img src="https://921544542-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiRQTWHUNVZ5tIxQJXclF%2Fuploads%2FUXCEW77E13l8ZNaR6zjH%2F1707453517262.png?alt=media&#x26;token=9d34ae59-d95a-4bb9-98be-01d4ac96c1f9" alt=""><figcaption><p>Docker Compose Workflow</p></figcaption></figure>

### Docker Vs Docker Compose

Docker is a containerization engine that provides a CLI for building, running, and managing individual containers on your host.

Compose is a tool that expands Docker with support for multi-container management. It supports “stacks” of containers that are declaratively defined in project-level config files.

### Docker Compose Benefits

* Fast and easy configuration with YAML scripts
* Single host deployment
* Increased productivity
* Security with isolated containers
