# Docker Compose

Deploy a docker-compose.yml on Hangar from your repository or pasted in, as Docker Compose on one node or as a Swarm stack across the region.

If your app is already described in a `docker-compose.yml`, you can deploy it as it is. A compose service on Hangar runs the whole file, with each of its services, as one unit in your project.

For a single app, a regular service is simpler: it gets [builds](https://tryhangar.io/docs/builds), [rollbacks](https://tryhangar.io/docs/deployments) and [preview deployments](https://tryhangar.io/docs/preview-deployments). Compose is the right fit when the file is the source of truth, for example software that ships with a compose file.

## Create a compose service

In a project, choose **New → Compose stack** and pick how it runs:

| Mode | Runs | Builds | Use it for |
|---|---|---|---|
| **Docker Compose** | `docker compose up` on one node | `build:` and `depends_on` work, like on your machine | most compose files |
| **Swarm stack** | `docker stack deploy` across the region's nodes | images must be prebuilt; `build:` is ignored | services you want to replicate |

Then set where the file comes from:

- **A repository**, from a connected [Git provider](https://tryhangar.io/docs/git-providers) or any public Git URL, with the path to the compose file. Pushes deploy it again, like any other service.
- **Raw**, by pasting the file into the editor. Good for a quick start or a file that does not live in a repository.

## Domains

A compose file can have many services, so a domain names the one it points to. In the compose service's networking settings, add a domain, choose the service in the file and the port it listens on. HTTPS certificates are issued and renewed as for any other domain; see [Domains and HTTPS](https://tryhangar.io/docs/domains).

You do not need `ports:` in the file for traffic that comes through a domain.

## Variables

Variables set on the compose service are available to the file. Reference them with `${NAME}` in the compose file, as you would with a `.env` next to it. Project and environment variables can be referenced too; see [Environment variables](https://tryhangar.io/docs/environment-variables).

## Logs and metrics

Logs, metrics and traces are collected for every container of the compose service; see [Observability](https://tryhangar.io/docs/observability). To run something on a schedule, deploy it as its own service with a [cron schedule](https://tryhangar.io/docs/cron-jobs).

## What you pay for

A compose service is metered like any other: the CPU and memory its containers use, the storage of its volumes and its egress. See [Pricing](https://tryhangar.io/pricing).

## Frequently asked questions

### Can I deploy an existing docker-compose.yml on Hangar?

Yes. Add a compose stack, point it at the repository that holds the file or paste the file in, and deploy. Each service in the file can get its own domain.

### What is the difference between Docker Compose and Swarm stack on Hangar?

Docker Compose runs docker compose up on a single node and supports build and depends_on, like on your machine. Swarm stack runs docker stack deploy so services can replicate across the region's nodes, but images must be prebuilt and build is ignored.
