2015-06-07 22:59:58 +02:00
|
|
|
<!--[metadata]>
|
|
|
|
+++
|
2016-01-29 00:53:40 +01:00
|
|
|
title = "Using Compose in Production"
|
2015-06-07 22:59:58 +02:00
|
|
|
description = "Guide to using Docker Compose in production"
|
|
|
|
keywords = ["documentation, docs, docker, compose, orchestration, containers, production"]
|
|
|
|
[menu.main]
|
2016-01-24 21:03:44 +01:00
|
|
|
parent="workw_compose"
|
2016-01-29 00:50:05 +01:00
|
|
|
weight=22
|
2015-06-07 22:59:58 +02:00
|
|
|
+++
|
|
|
|
<![end-metadata]-->
|
2015-04-04 00:26:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
## Using Compose in production
|
|
|
|
|
2015-10-21 23:17:38 +02:00
|
|
|
> Compose is still primarily aimed at development and testing environments.
|
|
|
|
> Compose may be used for smaller production deployments, but is probably
|
|
|
|
> not yet suitable for larger deployments.
|
2015-04-04 00:26:02 +02:00
|
|
|
|
|
|
|
When deploying to production, you'll almost certainly want to make changes to
|
2015-04-07 01:47:07 +02:00
|
|
|
your app configuration that are more appropriate to a live environment. These
|
|
|
|
changes may include:
|
2015-04-04 00:26:02 +02:00
|
|
|
|
|
|
|
- Removing any volume bindings for application code, so that code stays inside
|
|
|
|
the container and can't be changed from outside
|
|
|
|
- Binding to different ports on the host
|
2015-04-07 01:47:07 +02:00
|
|
|
- Setting environment variables differently (e.g., to decrease the verbosity of
|
2015-04-04 00:26:02 +02:00
|
|
|
logging, or to enable email sending)
|
2015-04-07 01:47:07 +02:00
|
|
|
- Specifying a restart policy (e.g., `restart: always`) to avoid downtime
|
|
|
|
- Adding extra services (e.g., a log aggregator)
|
2015-04-04 00:26:02 +02:00
|
|
|
|
2015-10-21 23:17:38 +02:00
|
|
|
For this reason, you'll probably want to define an additional Compose file, say
|
|
|
|
`production.yml`, which specifies production-appropriate
|
|
|
|
configuration. This configuration file only needs to include the changes you'd
|
|
|
|
like to make from the original Compose file. The additional Compose file
|
|
|
|
can be applied over the original `docker-compose.yml` to create a new configuration.
|
2015-04-04 00:26:02 +02:00
|
|
|
|
2015-10-21 23:17:38 +02:00
|
|
|
Once you've got a second configuration file, tell Compose to use it with the
|
|
|
|
`-f` option:
|
2015-04-04 00:26:02 +02:00
|
|
|
|
2015-10-21 23:17:38 +02:00
|
|
|
$ docker-compose -f docker-compose.yml -f production.yml up -d
|
2015-04-04 00:26:02 +02:00
|
|
|
|
2015-10-09 18:56:59 +02:00
|
|
|
See [Using multiple compose files](extends.md#different-environments) for a more
|
|
|
|
complete example.
|
|
|
|
|
2015-04-04 00:26:02 +02:00
|
|
|
### Deploying changes
|
|
|
|
|
|
|
|
When you make changes to your app code, you'll need to rebuild your image and
|
2015-04-07 01:47:07 +02:00
|
|
|
recreate your app's containers. To redeploy a service called
|
|
|
|
`web`, you would use:
|
2015-04-04 00:26:02 +02:00
|
|
|
|
|
|
|
$ docker-compose build web
|
|
|
|
$ docker-compose up --no-deps -d web
|
|
|
|
|
2015-04-07 01:47:07 +02:00
|
|
|
This will first rebuild the image for `web` and then stop, destroy, and recreate
|
2015-04-04 00:26:02 +02:00
|
|
|
*just* the `web` service. The `--no-deps` flag prevents Compose from also
|
|
|
|
recreating any services which `web` depends on.
|
|
|
|
|
2015-04-07 01:47:07 +02:00
|
|
|
### Running Compose on a single server
|
2015-04-04 00:26:02 +02:00
|
|
|
|
|
|
|
You can use Compose to deploy an app to a remote Docker host by setting the
|
2015-04-07 01:47:07 +02:00
|
|
|
`DOCKER_HOST`, `DOCKER_TLS_VERIFY`, and `DOCKER_CERT_PATH` environment variables
|
|
|
|
appropriately. For tasks like this,
|
2015-12-21 01:52:54 +01:00
|
|
|
[Docker Machine](https://docs.docker.com/machine/) makes managing local and
|
2015-04-07 01:47:07 +02:00
|
|
|
remote Docker hosts very easy, and is recommended even if you're not deploying
|
|
|
|
remotely.
|
2015-04-04 00:26:02 +02:00
|
|
|
|
|
|
|
Once you've set up your environment variables, all the normal `docker-compose`
|
2015-04-07 01:47:07 +02:00
|
|
|
commands will work with no further configuration.
|
2015-04-04 00:26:02 +02:00
|
|
|
|
2015-04-07 01:47:07 +02:00
|
|
|
### Running Compose on a Swarm cluster
|
2015-04-04 00:26:02 +02:00
|
|
|
|
2015-12-21 01:52:54 +01:00
|
|
|
[Docker Swarm](https://docs.docker.com/swarm/), a Docker-native clustering
|
2015-04-04 00:26:02 +02:00
|
|
|
system, exposes the same API as a single Docker host, which means you can use
|
|
|
|
Compose against a Swarm instance and run your apps across multiple hosts.
|
|
|
|
|
|
|
|
Compose/Swarm integration is still in the experimental stage, and Swarm is still
|
2015-08-11 18:38:49 +02:00
|
|
|
in beta, but if you'd like to explore and experiment, check out the <a
|
|
|
|
href="https://github.com/docker/compose/blob/master/SWARM.md">integration
|
|
|
|
guide</a>.
|
2015-05-12 13:44:43 +02:00
|
|
|
|
|
|
|
## Compose documentation
|
|
|
|
|
|
|
|
- [Installing Compose](install.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)
|