@@ -58,6 +58,36 @@ Each service will run in its own container. Using swarm mode,
58
58
we can also scale the application to deploy replicas
59
59
of containerized services distributed across multiple nodes.
60
60
61
+ Here is an example of one of the services fully defined:
62
+
63
+ ```
64
+ vote:
65
+ image: dockersamples/examplevotingapp_vote:before
66
+ ports:
67
+ - 5000:80
68
+ networks:
69
+ - frontend
70
+ depends_on:
71
+ - redis
72
+ deploy:
73
+ replicas: 2
74
+ update_config:
75
+ parallelism: 2
76
+ restart_policy:
77
+ condition: on-failure
78
+ ```
79
+
80
+ The ` image ` key defines which image the service will use. The ` vote ` service
81
+ uses ` dockersamples/examplevotingapp_vote:before ` .
82
+
83
+ The ` depends_on ` key allows you to specify that a service is only
84
+ deployed after another service. In our example, ` vote ` only deploys
85
+ after ` redis ` .
86
+
87
+ The ` deploy ` key specifies aspects of a swarm deployment, as described below in
88
+ [ Compose v.3 features and
89
+ compatibility] ( #compose-v3-features-and-compatibility ) .
90
+
61
91
## docker-stack.yml
62
92
63
93
We'll deploy the app using ` docker-stack.yml ` , which is a
@@ -68,8 +98,8 @@ To follow along with the example, you need only have
68
98
Docker running and the copy of ` docker-stack.yml ` we
69
99
provide here. This file defines all the services shown
70
100
in the [ table above] ( #anatomy-of-the-voting-app ) , their
71
- base images, configuration details such as ports
72
- and dependencies, and the swarm configuration.
101
+ base images, configuration details such as ports and networks,
102
+ application dependencies, and the swarm configuration.
73
103
74
104
```
75
105
version: "3"
@@ -167,60 +197,27 @@ To deploy the voting application, we will use the `docker-stack deploy` command
167
197
with this ` docker-stack.yml ` file to pull the referenced images and launch the
168
198
services in a swarm as configured in the ` .yml ` .
169
199
170
- Note that at the top of the ` docker-stack.yml ` file, the
171
- version is indicated as ` version: "3" ` . This voting app
172
- example relies on Compose version 3 features .
200
+ Note that at the top of the ` docker-stack.yml ` file, the version is indicated as
201
+ ` version: "3" ` . The voting app example relies on Compose version 3, which is
202
+ designed to be cross-compatible with Compose and Docker Engine swarm mode .
173
203
174
- Before we get started, let's take
175
- a look at some aspects of Compose files and deployment
176
- options that are new in Compose v.3, and that we want
177
- to highlight in this walkthrough.
204
+ Before we get started, let's take a look at some aspects of Compose files and
205
+ deployment options that are new in Compose v.3, and that we want to highlight in
206
+ this walkthrough.
178
207
179
208
- [ docker-stack.yml] ( #docker-stackyml )
180
- - [ services key] ( #services-key )
181
- - [ image key] ( #image-key )
182
209
- [ deploy key] ( #deploy-key )
183
- - [ depends_on key] ( #dependson-key )
184
210
- [ docker stack deploy command] ( #docker-stack-deploy-command )
185
- - [ Application stacks and services] ( #application-stacks -and-services )
211
+ - [ Application stacks and services] ( #application-stack -and-services )
186
212
187
213
### docker-stack.yml
188
214
189
215
` docker-stack.yml ` is a new type of Compose file only compatible with Compose
190
216
v.3.
191
217
192
- #### services key
193
-
194
- ` services ` is a new top-level key, under which there is a separate key for each
195
- of the services.
196
-
197
- Here is an example of one of the services:
198
-
199
- ```
200
- vote:
201
- image: dockersamples/examplevotingapp_vote:before
202
- ports:
203
- - 5000:80
204
- networks:
205
- - frontend
206
- depends_on:
207
- - redis
208
- deploy:
209
- replicas: 2
210
- update_config:
211
- parallelism: 2
212
- restart_policy:
213
- condition: on-failure
214
- ```
215
-
216
- #### image key
217
-
218
- The ` image ` key defines which image the service will use. The ` vote ` service
219
- uses ` dockersamples/examplevotingapp_vote:before ` .
220
-
221
218
#### deploy key
222
219
223
- The ` deploy ` key is new in v.3, and allows you to specify various properties of
220
+ The ` deploy ` key allows you to specify various properties of
224
221
a swarm deployment.
225
222
226
223
For example, the voting app configuration uses this to
@@ -230,12 +227,6 @@ be deployed to the swarm).
230
227
The voting app also uses the ` deploy ` key to
231
228
constrain some services to run only on the manager node.
232
229
233
- #### depends_on key
234
-
235
- The ` depends_on ` key allows you to specify that a service is only
236
- deployed after another service. In our example, ` vote ` only deploys
237
- after ` redis ` .
238
-
239
230
### docker stack deploy command
240
231
241
232
` docker stack deploy ` is the command we will use to deploy with
@@ -254,10 +245,20 @@ v.3 compatible applications.
254
245
255
246
Taken together, these new features and deployment options can help when
256
247
mapping out distributed applications and clustering strategies. Rather than
257
- thinking about running individual containers, perse, we can start to model
248
+ thinking about running individual containers, we can start to model
258
249
Docker deployments as application stacks and services.
259
250
260
- For more about ` docker-stack.yml ` and the ` docker stack deploy ` command, see [ deploy] ( /compose/compose-file.md#deploy ) in the [ Compose file reference] ( /compose/compose-file.md ) .
251
+ ### Compose file reference
252
+
253
+ To learn more, see these topics in the [ Compose file
254
+ reference] ( /compose/compose-file.md ) :
255
+
256
+ * For more about ` docker-stack.yml ` and the ` docker stack deploy ` command, see
257
+ [ deploy] ( /compose/compose-file.md#deploy ) .
258
+
259
+ * For more on what's new in Compose v.3, see
260
+ [ Versioning] ( /compose/compose-file.md#versioning ) , [ Version 3] ( /compose/compose-file.md#version-3 ) , and
261
+ [ Upgrading] ( /compose/compose-file.md#upgrading ) .
261
262
262
263
## What's next?
263
264
0 commit comments