github.com/trgill/moby@v1.13.1/experimental/docker-stacks-and-bundles.md (about)

     1  # Docker Stacks and Distributed Application Bundles
     2  
     3  ## Overview
     4  
     5  Docker Stacks and Distributed Application Bundles are experimental features
     6  introduced in Docker 1.12 and Docker Compose 1.8, alongside the concept of
     7  swarm mode, and Nodes and Services in the Engine API.
     8  
     9  A Dockerfile can be built into an image, and containers can be created from
    10  that image. Similarly, a docker-compose.yml can be built into a **distributed
    11  application bundle**, and **stacks** can be created from that bundle. In that
    12  sense, the bundle is a multi-services distributable image format.
    13  
    14  As of Docker 1.12 and Compose 1.8, the features are experimental. Neither
    15  Docker Engine nor the Docker Registry support distribution of bundles.
    16  
    17  ## Producing a bundle
    18  
    19  The easiest way to produce a bundle is to generate it using `docker-compose`
    20  from an existing `docker-compose.yml`. Of course, that's just *one* possible way
    21  to proceed, in the same way that `docker build` isn't the only way to produce a
    22  Docker image.
    23  
    24  From `docker-compose`:
    25  
    26  ```bash
    27  $ docker-compose bundle
    28  WARNING: Unsupported key 'network_mode' in services.nsqd - ignoring
    29  WARNING: Unsupported key 'links' in services.nsqd - ignoring
    30  WARNING: Unsupported key 'volumes' in services.nsqd - ignoring
    31  [...]
    32  Wrote bundle to vossibility-stack.dab
    33  ```
    34  
    35  ## Creating a stack from a bundle
    36  
    37  A stack is created using the `docker deploy` command:
    38  
    39  ```bash
    40  # docker deploy --help
    41  
    42  Usage:  docker deploy [OPTIONS] STACK
    43  
    44  Create and update a stack from a Distributed Application Bundle (DAB)
    45  
    46  Options:
    47        --file   string        Path to a Distributed Application Bundle file (Default: STACK.dab)
    48        --help                 Print usage
    49        --with-registry-auth   Send registry authentication details to Swarm agents
    50  ```
    51  
    52  Let's deploy the stack created before:
    53  
    54  ```bash
    55  # docker deploy vossibility-stack
    56  Loading bundle from vossibility-stack.dab
    57  Creating service vossibility-stack_elasticsearch
    58  Creating service vossibility-stack_kibana
    59  Creating service vossibility-stack_logstash
    60  Creating service vossibility-stack_lookupd
    61  Creating service vossibility-stack_nsqd
    62  Creating service vossibility-stack_vossibility-collector
    63  ```
    64  
    65  We can verify that services were correctly created:
    66  
    67  ```bash
    68  $ docker service ls
    69  ID            NAME                                     MODE         REPLICAS    IMAGE
    70  29bv0vnlm903  vossibility-stack_lookupd                replicated   1/1         nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662
    71  4awt47624qwh  vossibility-stack_nsqd                   replicated   1/1         nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662
    72  4tjx9biia6fs  vossibility-stack_elasticsearch          replicated   1/1         elasticsearch@sha256:12ac7c6af55d001f71800b83ba91a04f716e58d82e748fa6e5a7359eed2301aa
    73  7563uuzr9eys  vossibility-stack_kibana                 replicated   1/1         kibana@sha256:6995a2d25709a62694a937b8a529ff36da92ebee74bafd7bf00e6caf6db2eb03
    74  9gc5m4met4he  vossibility-stack_logstash               replicated   1/1         logstash@sha256:2dc8bddd1bb4a5a34e8ebaf73749f6413c101b2edef6617f2f7713926d2141fe
    75  axqh55ipl40h  vossibility-stack_vossibility-collector  replicated   1/1         icecrime/vossibility-collector@sha256:f03f2977203ba6253988c18d04061c5ec7aab46bca9dfd89a9a1fa4500989fba
    76  ```
    77  
    78  ## Managing stacks
    79  
    80  Stacks are managed using the `docker stack` command:
    81  
    82  ```bash
    83  # docker stack --help
    84  
    85  Usage:  docker stack COMMAND
    86  
    87  Manage Docker stacks
    88  
    89  Options:
    90        --help   Print usage
    91  
    92  Commands:
    93    config      Print the stack configuration
    94    deploy      Create and update a stack
    95    ls          List stacks
    96    rm          Remove the stack
    97    services    List the services in the stack
    98    tasks       List the tasks in the stack
    99  
   100  Run 'docker stack COMMAND --help' for more information on a command.
   101  ```
   102  
   103  ## Bundle file format
   104  
   105  Distributed application bundles are described in a JSON format. When bundles
   106  are persisted as files, the file extension is `.dab` (Docker 1.12RC2 tools use
   107  `.dsb` for the file extension—this will be updated in the next release client).
   108  
   109  A bundle has two top-level fields: `version` and `services`. The version used
   110  by Docker 1.12 tools is `0.1`.
   111  
   112  `services` in the bundle are the services that comprise the app. They
   113  correspond to the new `Service` object introduced in the 1.12 Docker Engine API.
   114  
   115  A service has the following fields:
   116  
   117  <dl>
   118      <dt>
   119          Image (required) <code>string</code>
   120      </dt>
   121      <dd>
   122          The image that the service will run. Docker images should be referenced
   123          with full content hash to fully specify the deployment artifact for the
   124          service. Example:
   125          <code>postgres@sha256:f76245b04ddbcebab5bb6c28e76947f49222c99fec4aadb0bb
   126          1c24821a 9e83ef</code>
   127      </dd>
   128      <dt>
   129          Command <code>[]string</code>
   130      </dt>
   131      <dd>
   132          Command to run in service containers.
   133      </dd>
   134      <dt>
   135          Args <code>[]string</code>
   136      </dt>
   137      <dd>
   138          Arguments passed to the service containers.
   139      </dd>
   140      <dt>
   141          Env <code>[]string</code>
   142      </dt>
   143      <dd>
   144          Environment variables.
   145      </dd>
   146      <dt>
   147          Labels <code>map[string]string</code>
   148      </dt>
   149      <dd>
   150          Labels used for setting meta data on services.
   151      </dd>
   152      <dt>
   153          Ports <code>[]Port</code>
   154      </dt>
   155      <dd>
   156          Service ports (composed of <code>Port</code> (<code>int</code>) and
   157          <code>Protocol</code> (<code>string</code>). A service description can
   158          only specify the container port to be exposed. These ports can be
   159          mapped on runtime hosts at the operator's discretion.
   160      </dd>
   161  
   162      <dt>
   163          WorkingDir <code>string</code>
   164      </dt>
   165      <dd>
   166          Working directory inside the service containers.
   167      </dd>
   168  
   169      <dt>
   170          User <code>string</code>
   171      </dt>
   172      <dd>
   173          Username or UID (format: <code>&lt;name|uid&gt;[:&lt;group|gid&gt;]</code>).
   174      </dd>
   175  
   176      <dt>
   177          Networks <code>[]string</code>
   178      </dt>
   179      <dd>
   180          Networks that the service containers should be connected to. An entity
   181          deploying a bundle should create networks as needed.
   182      </dd>
   183  </dl>
   184  
   185  The following is an example of bundlefile with two services:
   186  
   187  ```json
   188  {
   189  	"Version": "0.1",
   190  	"Services": {
   191  		"redis": {
   192  			"Image": "redis@sha256:4b24131101fa0117bcaa18ac37055fffd9176aa1a240392bb8ea85e0be50f2ce",
   193  			"Networks": ["default"]
   194  		},
   195  		"web": {
   196  			"Image": "dockercloud/hello-world@sha256:fe79a2cfbd17eefc344fb8419420808df95a1e22d93b7f621a7399fd1e9dca1d",
   197  			"Networks": ["default"],
   198  			"User": "web"
   199  		}
   200  	}
   201  }
   202  ```