> For the complete documentation index, see [llms.txt](https://notebook.iuriioapps.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notebook.iuriioapps.com/containers-and-microservices/docker/compose.md).

# Compose

### Why

* Configure relationships between containers
* Save docker container run settings in easy-to-read file
* create one-liner development environment startups

Comprised of 2 separate but related things:

* YAML formatted file that describes solution options for:
  * containers
  * volumes
  * networks
* A CLI tool docker-compose used for local dev/test automation

Installed automatically on Mac and Windows with Docker Desktop, for Linux must be downloaded separately.

### Links

* [Compose on GitHub](https://github.com/docker/compose)
* [Compose documentation](https://docs.docker.com/compose/compose-file/)

### Example

```yaml
version: '3'

services:
  drupal:
    image: drupal:8-apache
    ports:
    - '8080:80'
    volumes:
    - drupal-modules:/var/www/html/modules
    - drupal-profiles:/var/www/html/profiles
    - drupal-sites:/var/www/html/sites
    - drupal-themes:/var/www/html/themes
    restart: always
  postgres:
    image: postgres:10
    environment:
      POSTGRES_PASSWORD: pgPass@1
    restart: always

volumes:
  drupal-modules:
  drupal-profiles:
  drupal-sites:
  drupal-themes:

```

Commands

To start

```yaml
docker-compose up [--build] [...options]
```

To tear down

```yaml
docker-compose down [-v] [...other options]
```

### Using compose with build

* compose can also build your images
* will build them with `docker-compose up` if not found in cache
* also rebuild with `docker-compose build`
* great for complex builds that have lots of vars or build args

Example

```yaml
version: '3'

services:
  proxy:
    build:
      context: .
      dockerfile: nginx.Dockerfile
    image: nginx-custom
    ports:
    - '80:80'
  web:
    image: httpd
    volumes:
    - ./html:/usr/local/apache2/htdocs/
```

### Restart policies

* `"no"` - never attempt to restart this container if it stops or crashes (must be in "")
* `always` - if this container stops, for any reason, always attempt to restart it
* `on-failure` - only restart if the container stops with an error code
* `unless-stopped` - always restart unless we forcibly stop it


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://notebook.iuriioapps.com/containers-and-microservices/docker/compose.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
