2015-06-07 22:59:58 +02:00
|
|
|
<!--[metadata]>
|
|
|
|
+++
|
|
|
|
title = "Overview of Docker Compose"
|
|
|
|
description = "Introduction and Overview of Compose"
|
|
|
|
keywords = ["documentation, docs, docker, compose, orchestration, containers"]
|
|
|
|
[menu.main]
|
|
|
|
parent="smn_workw_compose"
|
|
|
|
+++
|
|
|
|
<![end-metadata]-->
|
2014-01-27 12:42:38 +01:00
|
|
|
|
2015-01-19 06:46:23 +01:00
|
|
|
|
2015-06-07 22:59:58 +02:00
|
|
|
# Overview of Docker Compose
|
2015-04-07 01:47:07 +02:00
|
|
|
|
2015-10-09 17:08:23 +02:00
|
|
|
Compose is a tool for defining and running multi-container Docker applications.
|
2015-10-30 18:27:06 +01:00
|
|
|
With Compose, you use a Compose file to configure your application's services.
|
|
|
|
Then, using a single command, you create and start all the services
|
2015-10-09 17:08:23 +02:00
|
|
|
from your configuration. To learn more about all the features of Compose
|
2015-10-30 18:27:06 +01:00
|
|
|
see [the list of features](#features).
|
2015-01-30 03:21:49 +01:00
|
|
|
|
2015-10-09 17:08:23 +02:00
|
|
|
Compose is great for development, testing, and staging environments, as well as
|
|
|
|
CI workflows. You can learn more about each case in
|
|
|
|
[Common Use Cases](#common-use-cases).
|
2015-01-30 03:21:49 +01:00
|
|
|
|
|
|
|
Using Compose is basically a three-step process.
|
2015-01-30 12:27:57 +01:00
|
|
|
|
2015-03-27 00:35:53 +01:00
|
|
|
1. Define your app's environment with a `Dockerfile` so it can be
|
|
|
|
reproduced anywhere.
|
|
|
|
2. Define the services that make up your app in `docker-compose.yml` so
|
2015-10-09 17:08:23 +02:00
|
|
|
they can be run together in an isolated environment.
|
2015-03-27 00:35:53 +01:00
|
|
|
3. Lastly, run `docker-compose up` and Compose will start and run your entire app.
|
|
|
|
|
|
|
|
A `docker-compose.yml` looks like this:
|
2014-01-27 12:42:38 +01:00
|
|
|
|
2015-11-19 02:45:10 +01:00
|
|
|
version: 2
|
|
|
|
services:
|
|
|
|
web:
|
|
|
|
build: .
|
|
|
|
ports:
|
|
|
|
- "5000:5000"
|
|
|
|
volumes:
|
|
|
|
- .:/code
|
|
|
|
- logvolume01:/var/log
|
|
|
|
links:
|
|
|
|
- redis
|
|
|
|
redis:
|
|
|
|
image: redis
|
|
|
|
volumes:
|
2016-01-19 21:03:41 +01:00
|
|
|
logvolume01: {}
|
2014-01-27 12:42:38 +01:00
|
|
|
|
2015-10-09 17:08:23 +02:00
|
|
|
For more information about the Compose file, see the
|
2015-10-23 22:51:03 +02:00
|
|
|
[Compose file reference](compose-file.md)
|
2015-10-09 17:08:23 +02:00
|
|
|
|
2015-02-16 20:21:17 +01:00
|
|
|
Compose has commands for managing the whole lifecycle of your application:
|
2014-01-27 12:42:38 +01:00
|
|
|
|
2015-01-30 03:21:49 +01:00
|
|
|
* Start, stop and rebuild services
|
|
|
|
* View the status of running services
|
2015-02-16 20:21:17 +01:00
|
|
|
* Stream the log output of running services
|
|
|
|
* Run a one-off command on a service
|
2014-01-27 12:42:38 +01:00
|
|
|
|
2015-02-25 15:09:30 +01:00
|
|
|
## Compose documentation
|
|
|
|
|
|
|
|
- [Installing Compose](install.md)
|
2015-10-09 16:49:41 +02:00
|
|
|
- [Getting Started](gettingstarted.md)
|
2015-05-12 13:44:43 +02:00
|
|
|
- [Get started with Django](django.md)
|
|
|
|
- [Get started with Rails](rails.md)
|
2015-09-16 17:01:43 +02:00
|
|
|
- [Get started with WordPress](wordpress.md)
|
2015-10-22 02:13:43 +02:00
|
|
|
- [Frequently asked questions](faq.md)
|
2015-10-13 13:01:19 +02:00
|
|
|
- [Command line reference](./reference/index.md)
|
2015-10-13 21:23:27 +02:00
|
|
|
- [Compose file reference](compose-file.md)
|
2014-01-27 12:42:38 +01:00
|
|
|
|
2015-10-09 17:08:23 +02:00
|
|
|
## Features
|
|
|
|
|
2015-10-23 22:51:03 +02:00
|
|
|
The features of Compose that make it effective are:
|
|
|
|
|
2015-10-27 21:51:49 +01:00
|
|
|
* [Multiple isolated environments on a single host](#Multiple-isolated-environments-on-a-single-host)
|
|
|
|
* [Preserve volume data when containers are created](#preserve-volume-data-when-containers-are-created)
|
2015-10-23 22:51:03 +02:00
|
|
|
* [Only recreate containers that have changed](#only-recreate-containers-that-have-changed)
|
|
|
|
* [Variables and moving a composition between environments](#variables-and-moving-a-composition-between-environments)
|
|
|
|
|
2015-10-27 21:51:49 +01:00
|
|
|
#### Multiple isolated environments on a single host
|
|
|
|
|
|
|
|
Compose uses a project name to isolate environments from each other. You can use
|
|
|
|
this project name to:
|
|
|
|
|
|
|
|
* on a dev host, to create multiple copies of a single environment (ex: you want
|
|
|
|
to run a stable copy for each feature branch of a project)
|
|
|
|
* on a CI server, to keep builds from interfering with each other, you can set
|
|
|
|
the project name to a unique build number
|
|
|
|
* on a shared host or dev host, to prevent different projects which may use the
|
|
|
|
same service names, from interfering with each other
|
|
|
|
|
|
|
|
The default project name is the basename of the project directory. You can set
|
|
|
|
a custom project name by using the
|
|
|
|
[`-p` command line option](./reference/docker-compose.md) or the
|
|
|
|
[`COMPOSE_PROJECT_NAME` environment variable](./reference/overview.md#compose-project-name).
|
|
|
|
|
|
|
|
#### Preserve volume data when containers are created
|
2015-10-09 17:08:23 +02:00
|
|
|
|
|
|
|
Compose preserves all volumes used by your services. When `docker-compose up`
|
|
|
|
runs, if it finds any containers from previous runs, it copies the volumes from
|
|
|
|
the old container to the new container. This process ensures that any data
|
|
|
|
you've created in volumes isn't lost.
|
|
|
|
|
|
|
|
|
|
|
|
#### Only recreate containers that have changed
|
|
|
|
|
|
|
|
Compose caches the configuration used to create a container. When you
|
|
|
|
restart a service that has not changed, Compose re-uses the existing
|
|
|
|
containers. Re-using containers means that you can make changes to your
|
|
|
|
environment very quickly.
|
|
|
|
|
|
|
|
|
2015-10-23 22:51:03 +02:00
|
|
|
#### Variables and moving a composition between environments
|
2015-10-09 17:08:23 +02:00
|
|
|
|
|
|
|
Compose supports variables in the Compose file. You can use these variables
|
|
|
|
to customize your composition for different environments, or different users.
|
|
|
|
See [Variable substitution](compose-file.md#variable-substitution) for more
|
|
|
|
details.
|
|
|
|
|
2015-10-23 22:51:03 +02:00
|
|
|
You can extend a Compose file using the `extends` field or by creating multiple
|
|
|
|
Compose files. See [extends](extends.md) for more details.
|
2015-10-09 17:08:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
## Common Use Cases
|
|
|
|
|
|
|
|
Compose can be used in many different ways. Some common use cases are outlined
|
|
|
|
below.
|
|
|
|
|
|
|
|
### Development environments
|
|
|
|
|
2015-10-23 22:51:03 +02:00
|
|
|
When you're developing software, the ability to run an application in an
|
|
|
|
isolated environment and interact with it is crucial. The Compose command
|
|
|
|
line tool can be used to create the environment and interact with it.
|
|
|
|
|
|
|
|
The [Compose file](compose-file.md) provides a way to document and configure
|
|
|
|
all of the application's service dependencies (databases, queues, caches,
|
|
|
|
web service APIs, etc). Using the Compose command line tool you can create
|
|
|
|
and start one or more containers for each dependency with a single command
|
|
|
|
(`docker-compose up`).
|
|
|
|
|
|
|
|
Together, these features provide a convenient way for developers to get
|
|
|
|
started on a project. Compose can reduce a multi-page "developer getting
|
|
|
|
started guide" to a single machine readable Compose file and a few commands.
|
2015-10-09 17:08:23 +02:00
|
|
|
|
|
|
|
### Automated testing environments
|
|
|
|
|
|
|
|
An important part of any Continuous Deployment or Continuous Integration process
|
|
|
|
is the automated test suite. Automated end-to-end testing requires an
|
|
|
|
environment in which to run tests. Compose provides a convenient way to create
|
|
|
|
and destroy isolated testing environments for your test suite. By defining the full
|
2015-10-23 22:51:03 +02:00
|
|
|
environment in a [Compose file](compose-file.md) you can create and destroy these
|
2015-10-09 17:08:23 +02:00
|
|
|
environments in just a few commands:
|
|
|
|
|
|
|
|
$ docker-compose up -d
|
|
|
|
$ ./run_tests
|
2016-01-12 23:33:17 +01:00
|
|
|
$ docker-compose down
|
2015-10-09 17:08:23 +02:00
|
|
|
|
|
|
|
### Single host deployments
|
|
|
|
|
|
|
|
Compose has traditionally been focused on development and testing workflows,
|
|
|
|
but with each release we're making progress on more production-oriented features.
|
2015-10-23 22:51:03 +02:00
|
|
|
You can use Compose to deploy to a remote Docker Engine. The Docker Engine may
|
|
|
|
be a single instance provisioned with
|
|
|
|
[Docker Machine](https://docs.docker.com/machine/) or an entire
|
|
|
|
[Docker Swarm](https://docs.docker.com/swarm/) cluster.
|
2015-10-09 17:08:23 +02:00
|
|
|
|
2015-10-23 22:51:03 +02:00
|
|
|
For details on using production-oriented features, see
|
|
|
|
[compose in production](production.md) in this documentation.
|
2015-10-09 17:08:23 +02:00
|
|
|
|
2015-05-26 16:41:59 +02:00
|
|
|
|
2015-04-07 01:47:07 +02:00
|
|
|
## Release Notes
|
|
|
|
|
2015-09-04 18:01:44 +02:00
|
|
|
To see a detailed list of changes for past and current releases of Docker
|
2015-10-09 17:08:23 +02:00
|
|
|
Compose, please refer to the
|
|
|
|
[CHANGELOG](https://github.com/docker/compose/blob/master/CHANGELOG.md).
|
2015-04-10 01:23:25 +02:00
|
|
|
|
|
|
|
## Getting help
|
|
|
|
|
2015-10-09 01:09:01 +02:00
|
|
|
Docker Compose is under active development. If you need help, would like to
|
|
|
|
contribute, or simply want to talk about the project with like-minded
|
|
|
|
individuals, we have a number of open channels for communication.
|
2015-04-10 01:23:25 +02:00
|
|
|
|
|
|
|
* To report bugs or file feature requests: please use the [issue tracker on Github](https://github.com/docker/compose/issues).
|
|
|
|
|
2015-10-09 01:09:01 +02:00
|
|
|
* To talk about the project with people in real time: please join the
|
|
|
|
`#docker-compose` channel on freenode IRC.
|
2015-04-10 01:23:25 +02:00
|
|
|
|
|
|
|
* To contribute code or documentation changes: please submit a [pull request on Github](https://github.com/docker/compose/pulls).
|
|
|
|
|
2015-12-21 01:52:54 +01:00
|
|
|
For more information and resources, please visit the [Getting Help project page](https://docs.docker.com/opensource/get-help/).
|