2016-06-20 00:27:55 -04:00
|
|
|
# Docker Stacks and Distributed Application Bundles
|
2016-06-14 18:31:45 -04:00
|
|
|
|
|
|
|
## Overview
|
|
|
|
|
2016-06-20 03:12:48 -04:00
|
|
|
Docker Stacks and Distributed Application Bundles are experimental features
|
|
|
|
introduced in Docker 1.12 and Docker Compose 1.8, alongside the concept of
|
|
|
|
swarm mode, and Nodes and Services in the Engine API.
|
2016-06-14 18:31:45 -04:00
|
|
|
|
2016-06-20 03:12:48 -04:00
|
|
|
A Dockerfile can be built into an image, and containers can be created from
|
|
|
|
that image. Similarly, a docker-compose.yml can be built into a **distributed
|
|
|
|
application bundle**, and **stacks** can be created from that bundle. In that
|
|
|
|
sense, the bundle is a multi-services distributable image format.
|
2016-06-14 18:31:45 -04:00
|
|
|
|
2016-06-20 03:12:48 -04:00
|
|
|
As of Docker 1.12 and Compose 1.8, the features are experimental. Neither
|
2016-12-21 07:05:19 -05:00
|
|
|
Docker Engine nor the Docker Registry supports distribution of bundles.
|
2016-06-14 18:31:45 -04:00
|
|
|
|
|
|
|
## Producing a bundle
|
|
|
|
|
|
|
|
The easiest way to produce a bundle is to generate it using `docker-compose`
|
|
|
|
from an existing `docker-compose.yml`. Of course, that's just *one* possible way
|
|
|
|
to proceed, in the same way that `docker build` isn't the only way to produce a
|
|
|
|
Docker image.
|
|
|
|
|
|
|
|
From `docker-compose`:
|
|
|
|
|
2016-06-20 03:12:48 -04:00
|
|
|
```bash
|
|
|
|
$ docker-compose bundle
|
|
|
|
WARNING: Unsupported key 'network_mode' in services.nsqd - ignoring
|
|
|
|
WARNING: Unsupported key 'links' in services.nsqd - ignoring
|
|
|
|
WARNING: Unsupported key 'volumes' in services.nsqd - ignoring
|
|
|
|
[...]
|
2016-06-25 13:08:03 -04:00
|
|
|
Wrote bundle to vossibility-stack.dab
|
2016-06-20 03:12:48 -04:00
|
|
|
```
|
2016-06-14 18:31:45 -04:00
|
|
|
|
|
|
|
## Creating a stack from a bundle
|
|
|
|
|
|
|
|
A stack is created using the `docker deploy` command:
|
|
|
|
|
2016-06-20 03:12:48 -04:00
|
|
|
```bash
|
2017-02-07 09:14:38 -05:00
|
|
|
$ docker deploy --help
|
2016-06-20 03:12:48 -04:00
|
|
|
Usage: docker deploy [OPTIONS] STACK
|
2016-06-14 18:31:45 -04:00
|
|
|
|
2017-02-07 09:14:38 -05:00
|
|
|
Deploy a new stack or update an existing stack
|
|
|
|
|
|
|
|
Aliases:
|
|
|
|
deploy, up
|
2016-06-14 18:31:45 -04:00
|
|
|
|
2016-06-20 03:12:48 -04:00
|
|
|
Options:
|
2017-02-07 09:14:38 -05:00
|
|
|
--bundle-file string Path to a Distributed Application Bundle file
|
|
|
|
-c, --compose-file string Path to a Compose file
|
|
|
|
--help Print usage
|
|
|
|
--with-registry-auth Send registry authentication details to Swarm agents
|
|
|
|
|
2016-06-20 03:12:48 -04:00
|
|
|
```
|
2016-06-14 18:31:45 -04:00
|
|
|
|
|
|
|
Let's deploy the stack created before:
|
|
|
|
|
2016-06-20 03:12:48 -04:00
|
|
|
```bash
|
2017-02-07 09:14:38 -05:00
|
|
|
$ docker deploy --bundle-file vossibility-stack.dab vossibility-stack
|
2016-06-25 13:08:03 -04:00
|
|
|
Loading bundle from vossibility-stack.dab
|
2016-06-20 03:12:48 -04:00
|
|
|
Creating service vossibility-stack_elasticsearch
|
|
|
|
Creating service vossibility-stack_kibana
|
|
|
|
Creating service vossibility-stack_logstash
|
|
|
|
Creating service vossibility-stack_lookupd
|
|
|
|
Creating service vossibility-stack_nsqd
|
|
|
|
Creating service vossibility-stack_vossibility-collector
|
|
|
|
```
|
2016-06-14 18:31:45 -04:00
|
|
|
|
|
|
|
We can verify that services were correctly created:
|
|
|
|
|
2016-06-20 03:12:48 -04:00
|
|
|
```bash
|
2016-10-24 23:39:53 -04:00
|
|
|
$ docker service ls
|
|
|
|
ID NAME MODE REPLICAS IMAGE
|
|
|
|
29bv0vnlm903 vossibility-stack_lookupd replicated 1/1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662
|
|
|
|
4awt47624qwh vossibility-stack_nsqd replicated 1/1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662
|
|
|
|
4tjx9biia6fs vossibility-stack_elasticsearch replicated 1/1 elasticsearch@sha256:12ac7c6af55d001f71800b83ba91a04f716e58d82e748fa6e5a7359eed2301aa
|
|
|
|
7563uuzr9eys vossibility-stack_kibana replicated 1/1 kibana@sha256:6995a2d25709a62694a937b8a529ff36da92ebee74bafd7bf00e6caf6db2eb03
|
|
|
|
9gc5m4met4he vossibility-stack_logstash replicated 1/1 logstash@sha256:2dc8bddd1bb4a5a34e8ebaf73749f6413c101b2edef6617f2f7713926d2141fe
|
|
|
|
axqh55ipl40h vossibility-stack_vossibility-collector replicated 1/1 icecrime/vossibility-collector@sha256:f03f2977203ba6253988c18d04061c5ec7aab46bca9dfd89a9a1fa4500989fba
|
2016-06-20 03:12:48 -04:00
|
|
|
```
|
2016-06-14 18:31:45 -04:00
|
|
|
|
|
|
|
## Managing stacks
|
|
|
|
|
2016-07-04 11:13:57 -04:00
|
|
|
Stacks are managed using the `docker stack` command:
|
2016-06-14 18:31:45 -04:00
|
|
|
|
2016-06-20 03:12:48 -04:00
|
|
|
```bash
|
|
|
|
# docker stack --help
|
|
|
|
|
|
|
|
Usage: docker stack COMMAND
|
|
|
|
|
|
|
|
Manage Docker stacks
|
|
|
|
|
|
|
|
Options:
|
|
|
|
--help Print usage
|
|
|
|
|
|
|
|
Commands:
|
2017-02-07 09:14:38 -05:00
|
|
|
deploy Deploy a new stack or update an existing stack
|
2016-06-23 01:00:21 -04:00
|
|
|
ls List stacks
|
2017-02-07 09:14:38 -05:00
|
|
|
ps List the tasks in the stack
|
2016-06-20 03:12:48 -04:00
|
|
|
rm Remove the stack
|
2016-07-01 22:12:16 -04:00
|
|
|
services List the services in the stack
|
2016-06-20 03:12:48 -04:00
|
|
|
|
|
|
|
Run 'docker stack COMMAND --help' for more information on a command.
|
|
|
|
```
|
2016-06-19 19:14:34 -04:00
|
|
|
|
|
|
|
## Bundle file format
|
|
|
|
|
2016-06-20 03:12:48 -04:00
|
|
|
Distributed application bundles are described in a JSON format. When bundles
|
|
|
|
are persisted as files, the file extension is `.dab` (Docker 1.12RC2 tools use
|
|
|
|
`.dsb` for the file extension—this will be updated in the next release client).
|
2016-06-19 19:14:34 -04:00
|
|
|
|
2016-06-20 03:12:48 -04:00
|
|
|
A bundle has two top-level fields: `version` and `services`. The version used
|
2017-02-07 09:14:38 -05:00
|
|
|
by Docker 1.12 and later tools is `0.1`.
|
2016-06-19 19:14:34 -04:00
|
|
|
|
2016-06-20 03:12:48 -04:00
|
|
|
`services` in the bundle are the services that comprise the app. They
|
|
|
|
correspond to the new `Service` object introduced in the 1.12 Docker Engine API.
|
2016-06-19 19:14:34 -04:00
|
|
|
|
|
|
|
A service has the following fields:
|
|
|
|
|
|
|
|
<dl>
|
|
|
|
<dt>
|
|
|
|
Image (required) <code>string</code>
|
|
|
|
</dt>
|
|
|
|
<dd>
|
2016-06-20 03:12:48 -04:00
|
|
|
The image that the service will run. Docker images should be referenced
|
|
|
|
with full content hash to fully specify the deployment artifact for the
|
|
|
|
service. Example:
|
|
|
|
<code>postgres@sha256:f76245b04ddbcebab5bb6c28e76947f49222c99fec4aadb0bb
|
|
|
|
1c24821a 9e83ef</code>
|
2016-06-19 19:14:34 -04:00
|
|
|
</dd>
|
|
|
|
<dt>
|
|
|
|
Command <code>[]string</code>
|
|
|
|
</dt>
|
|
|
|
<dd>
|
|
|
|
Command to run in service containers.
|
|
|
|
</dd>
|
|
|
|
<dt>
|
|
|
|
Args <code>[]string</code>
|
|
|
|
</dt>
|
|
|
|
<dd>
|
|
|
|
Arguments passed to the service containers.
|
|
|
|
</dd>
|
|
|
|
<dt>
|
|
|
|
Env <code>[]string</code>
|
|
|
|
</dt>
|
|
|
|
<dd>
|
|
|
|
Environment variables.
|
|
|
|
</dd>
|
|
|
|
<dt>
|
|
|
|
Labels <code>map[string]string</code>
|
|
|
|
</dt>
|
|
|
|
<dd>
|
|
|
|
Labels used for setting meta data on services.
|
|
|
|
</dd>
|
|
|
|
<dt>
|
|
|
|
Ports <code>[]Port</code>
|
|
|
|
</dt>
|
|
|
|
<dd>
|
2016-06-20 03:12:48 -04:00
|
|
|
Service ports (composed of <code>Port</code> (<code>int</code>) and
|
|
|
|
<code>Protocol</code> (<code>string</code>). A service description can
|
|
|
|
only specify the container port to be exposed. These ports can be
|
|
|
|
mapped on runtime hosts at the operator's discretion.
|
2016-06-19 19:14:34 -04:00
|
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
|
|
WorkingDir <code>string</code>
|
|
|
|
</dt>
|
|
|
|
<dd>
|
|
|
|
Working directory inside the service containers.
|
|
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
|
|
User <code>string</code>
|
|
|
|
</dt>
|
|
|
|
<dd>
|
2016-06-20 03:12:48 -04:00
|
|
|
Username or UID (format: <code><name|uid>[:<group|gid>]</code>).
|
2016-06-19 19:14:34 -04:00
|
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
|
|
Networks <code>[]string</code>
|
|
|
|
</dt>
|
|
|
|
<dd>
|
2016-06-20 03:12:48 -04:00
|
|
|
Networks that the service containers should be connected to. An entity
|
|
|
|
deploying a bundle should create networks as needed.
|
2016-06-19 19:14:34 -04:00
|
|
|
</dd>
|
|
|
|
</dl>
|
|
|
|
|
2016-07-25 15:37:56 -04:00
|
|
|
The following is an example of bundlefile with two services:
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"Version": "0.1",
|
|
|
|
"Services": {
|
|
|
|
"redis": {
|
|
|
|
"Image": "redis@sha256:4b24131101fa0117bcaa18ac37055fffd9176aa1a240392bb8ea85e0be50f2ce",
|
|
|
|
"Networks": ["default"]
|
|
|
|
},
|
|
|
|
"web": {
|
|
|
|
"Image": "dockercloud/hello-world@sha256:fe79a2cfbd17eefc344fb8419420808df95a1e22d93b7f621a7399fd1e9dca1d",
|
|
|
|
"Networks": ["default"],
|
|
|
|
"User": "web"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|