github.com/endophage/docker@v1.4.2-0.20161027011718-242853499895/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 REPLICAS IMAGE 70 COMMAND 71 29bv0vnlm903 vossibility-stack_lookupd 1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662 /nsqlookupd 72 4awt47624qwh vossibility-stack_nsqd 1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662 /nsqd --data-path=/data --lookupd-tcp-address=lookupd:4160 73 4tjx9biia6fs vossibility-stack_elasticsearch 1 elasticsearch@sha256:12ac7c6af55d001f71800b83ba91a04f716e58d82e748fa6e5a7359eed2301aa 74 7563uuzr9eys vossibility-stack_kibana 1 kibana@sha256:6995a2d25709a62694a937b8a529ff36da92ebee74bafd7bf00e6caf6db2eb03 75 9gc5m4met4he vossibility-stack_logstash 1 logstash@sha256:2dc8bddd1bb4a5a34e8ebaf73749f6413c101b2edef6617f2f7713926d2141fe logstash -f /etc/logstash/conf.d/logstash.conf 76 axqh55ipl40h vossibility-stack_vossibility-collector 1 icecrime/vossibility-collector@sha256:f03f2977203ba6253988c18d04061c5ec7aab46bca9dfd89a9a1fa4500989fba --config /config/config.toml --debug 77 ``` 78 79 ## Managing stacks 80 81 Stacks are managed using the `docker stack` command: 82 83 ```bash 84 # docker stack --help 85 86 Usage: docker stack COMMAND 87 88 Manage Docker stacks 89 90 Options: 91 --help Print usage 92 93 Commands: 94 config Print the stack configuration 95 deploy Create and update a stack 96 ls List stacks 97 rm Remove the stack 98 services List the services in the stack 99 tasks List the tasks in the stack 100 101 Run 'docker stack COMMAND --help' for more information on a command. 102 ``` 103 104 ## Bundle file format 105 106 Distributed application bundles are described in a JSON format. When bundles 107 are persisted as files, the file extension is `.dab` (Docker 1.12RC2 tools use 108 `.dsb` for the file extension—this will be updated in the next release client). 109 110 A bundle has two top-level fields: `version` and `services`. The version used 111 by Docker 1.12 tools is `0.1`. 112 113 `services` in the bundle are the services that comprise the app. They 114 correspond to the new `Service` object introduced in the 1.12 Docker Engine API. 115 116 A service has the following fields: 117 118 <dl> 119 <dt> 120 Image (required) <code>string</code> 121 </dt> 122 <dd> 123 The image that the service will run. Docker images should be referenced 124 with full content hash to fully specify the deployment artifact for the 125 service. Example: 126 <code>postgres@sha256:f76245b04ddbcebab5bb6c28e76947f49222c99fec4aadb0bb 127 1c24821a 9e83ef</code> 128 </dd> 129 <dt> 130 Command <code>[]string</code> 131 </dt> 132 <dd> 133 Command to run in service containers. 134 </dd> 135 <dt> 136 Args <code>[]string</code> 137 </dt> 138 <dd> 139 Arguments passed to the service containers. 140 </dd> 141 <dt> 142 Env <code>[]string</code> 143 </dt> 144 <dd> 145 Environment variables. 146 </dd> 147 <dt> 148 Labels <code>map[string]string</code> 149 </dt> 150 <dd> 151 Labels used for setting meta data on services. 152 </dd> 153 <dt> 154 Ports <code>[]Port</code> 155 </dt> 156 <dd> 157 Service ports (composed of <code>Port</code> (<code>int</code>) and 158 <code>Protocol</code> (<code>string</code>). A service description can 159 only specify the container port to be exposed. These ports can be 160 mapped on runtime hosts at the operator's discretion. 161 </dd> 162 163 <dt> 164 WorkingDir <code>string</code> 165 </dt> 166 <dd> 167 Working directory inside the service containers. 168 </dd> 169 170 <dt> 171 User <code>string</code> 172 </dt> 173 <dd> 174 Username or UID (format: <code><name|uid>[:<group|gid>]</code>). 175 </dd> 176 177 <dt> 178 Networks <code>[]string</code> 179 </dt> 180 <dd> 181 Networks that the service containers should be connected to. An entity 182 deploying a bundle should create networks as needed. 183 </dd> 184 </dl> 185 186 The following is an example of bundlefile with two services: 187 188 ```json 189 { 190 "Version": "0.1", 191 "Services": { 192 "redis": { 193 "Image": "redis@sha256:4b24131101fa0117bcaa18ac37055fffd9176aa1a240392bb8ea85e0be50f2ce", 194 "Networks": ["default"] 195 }, 196 "web": { 197 "Image": "dockercloud/hello-world@sha256:fe79a2cfbd17eefc344fb8419420808df95a1e22d93b7f621a7399fd1e9dca1d", 198 "Networks": ["default"], 199 "User": "web" 200 } 201 } 202 } 203 ```