github.com/yogeshlonkar/moby@v1.13.2-0.20201203103638-c0b64beaea94/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  Usage:  docker deploy [OPTIONS] STACK
    42  
    43  Deploy a new stack or update an existing stack
    44  
    45  Aliases:
    46    deploy, up
    47  
    48  Options:
    49        --bundle-file string    Path to a Distributed Application Bundle file
    50    -c, --compose-file string   Path to a Compose file
    51        --help                  Print usage
    52        --with-registry-auth    Send registry authentication details to Swarm agents
    53  
    54  ```
    55  
    56  Let's deploy the stack created before:
    57  
    58  ```bash
    59  $ docker deploy --bundle-file vossibility-stack.dab vossibility-stack
    60  Loading bundle from vossibility-stack.dab
    61  Creating service vossibility-stack_elasticsearch
    62  Creating service vossibility-stack_kibana
    63  Creating service vossibility-stack_logstash
    64  Creating service vossibility-stack_lookupd
    65  Creating service vossibility-stack_nsqd
    66  Creating service vossibility-stack_vossibility-collector
    67  ```
    68  
    69  We can verify that services were correctly created:
    70  
    71  ```bash
    72  $ docker service ls
    73  ID            NAME                                     MODE         REPLICAS    IMAGE
    74  29bv0vnlm903  vossibility-stack_lookupd                replicated   1/1         nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662
    75  4awt47624qwh  vossibility-stack_nsqd                   replicated   1/1         nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662
    76  4tjx9biia6fs  vossibility-stack_elasticsearch          replicated   1/1         elasticsearch@sha256:12ac7c6af55d001f71800b83ba91a04f716e58d82e748fa6e5a7359eed2301aa
    77  7563uuzr9eys  vossibility-stack_kibana                 replicated   1/1         kibana@sha256:6995a2d25709a62694a937b8a529ff36da92ebee74bafd7bf00e6caf6db2eb03
    78  9gc5m4met4he  vossibility-stack_logstash               replicated   1/1         logstash@sha256:2dc8bddd1bb4a5a34e8ebaf73749f6413c101b2edef6617f2f7713926d2141fe
    79  axqh55ipl40h  vossibility-stack_vossibility-collector  replicated   1/1         icecrime/vossibility-collector@sha256:f03f2977203ba6253988c18d04061c5ec7aab46bca9dfd89a9a1fa4500989fba
    80  ```
    81  
    82  ## Managing stacks
    83  
    84  Stacks are managed using the `docker stack` command:
    85  
    86  ```bash
    87  # docker stack --help
    88  
    89  Usage:  docker stack COMMAND
    90  
    91  Manage Docker stacks
    92  
    93  Options:
    94        --help   Print usage
    95  
    96  Commands:
    97    deploy      Deploy a new stack or update an existing stack
    98    ls          List stacks
    99    ps          List the tasks in the stack
   100    rm          Remove the stack
   101    services    List the services in the stack
   102  
   103  Run 'docker stack COMMAND --help' for more information on a command.
   104  ```
   105  
   106  ## Bundle file format
   107  
   108  Distributed application bundles are described in a JSON format. When bundles
   109  are persisted as files, the file extension is `.dab` (Docker 1.12RC2 tools use
   110  `.dsb` for the file extension—this will be updated in the next release client).
   111  
   112  A bundle has two top-level fields: `version` and `services`. The version used
   113  by Docker 1.12 and later tools is `0.1`.
   114  
   115  `services` in the bundle are the services that comprise the app. They
   116  correspond to the new `Service` object introduced in the 1.12 Docker Engine API.
   117  
   118  A service has the following fields:
   119  
   120  <dl>
   121      <dt>
   122          Image (required) <code>string</code>
   123      </dt>
   124      <dd>
   125          The image that the service will run. Docker images should be referenced
   126          with full content hash to fully specify the deployment artifact for the
   127          service. Example:
   128          <code>postgres@sha256:f76245b04ddbcebab5bb6c28e76947f49222c99fec4aadb0bb
   129          1c24821a 9e83ef</code>
   130      </dd>
   131      <dt>
   132          Command <code>[]string</code>
   133      </dt>
   134      <dd>
   135          Command to run in service containers.
   136      </dd>
   137      <dt>
   138          Args <code>[]string</code>
   139      </dt>
   140      <dd>
   141          Arguments passed to the service containers.
   142      </dd>
   143      <dt>
   144          Env <code>[]string</code>
   145      </dt>
   146      <dd>
   147          Environment variables.
   148      </dd>
   149      <dt>
   150          Labels <code>map[string]string</code>
   151      </dt>
   152      <dd>
   153          Labels used for setting meta data on services.
   154      </dd>
   155      <dt>
   156          Ports <code>[]Port</code>
   157      </dt>
   158      <dd>
   159          Service ports (composed of <code>Port</code> (<code>int</code>) and
   160          <code>Protocol</code> (<code>string</code>). A service description can
   161          only specify the container port to be exposed. These ports can be
   162          mapped on runtime hosts at the operator's discretion.
   163      </dd>
   164  
   165      <dt>
   166          WorkingDir <code>string</code>
   167      </dt>
   168      <dd>
   169          Working directory inside the service containers.
   170      </dd>
   171  
   172      <dt>
   173          User <code>string</code>
   174      </dt>
   175      <dd>
   176          Username or UID (format: <code>&lt;name|uid&gt;[:&lt;group|gid&gt;]</code>).
   177      </dd>
   178  
   179      <dt>
   180          Networks <code>[]string</code>
   181      </dt>
   182      <dd>
   183          Networks that the service containers should be connected to. An entity
   184          deploying a bundle should create networks as needed.
   185      </dd>
   186  </dl>
   187  
   188  The following is an example of bundlefile with two services:
   189  
   190  ```json
   191  {
   192  	"Version": "0.1",
   193  	"Services": {
   194  		"redis": {
   195  			"Image": "redis@sha256:4b24131101fa0117bcaa18ac37055fffd9176aa1a240392bb8ea85e0be50f2ce",
   196  			"Networks": ["default"]
   197  		},
   198  		"web": {
   199  			"Image": "dockercloud/hello-world@sha256:fe79a2cfbd17eefc344fb8419420808df95a1e22d93b7f621a7399fd1e9dca1d",
   200  			"Networks": ["default"],
   201  			"User": "web"
   202  		}
   203  	}
   204  }
   205  ```