Browse code

carries and closes 25414

Signed-off-by: Charles Smith <charles.smith@docker.com>

Charles Smith authored on 2016/09/09 04:10:04
Showing 1 changed files
... ...
@@ -48,8 +48,8 @@ Options:
48 48
   -w, --workdir string                 Working directory inside the container
49 49
 ```
50 50
 
51
-Creates a service as described by the specified parameters. This command has to
52
-be run targeting a manager node.
51
+Creates a service as described by the specified parameters. You must run this
52
+command on a manager node.
53 53
 
54 54
 ## Examples
55 55
 
... ...
@@ -64,10 +64,10 @@ ID            NAME   REPLICAS  IMAGE        COMMAND
64 64
 dmu1ept4cxcf  redis  1/1       redis:3.0.6
65 65
 ```
66 66
 
67
-### Create a service with 5 tasks
67
+### Create a service with 5 replica tasks (--replicas)
68 68
 
69
-You can set the number of tasks for a service using the `--replicas` option. The
70
-following command creates a `redis` service with `5` tasks:
69
+Use the `--replicas` flag to set the number of replica tasks for a replicated
70
+service. The following command creates a `redis` service with `5` replica tasks:
71 71
 
72 72
 ```bash
73 73
 $ docker service create --name redis --replicas=5 redis:3.0.6
... ...
@@ -75,12 +75,12 @@ $ docker service create --name redis --replicas=5 redis:3.0.6
75 75
 ```
76 76
 
77 77
 The above command sets the *desired* number of tasks for the service. Even
78
-though the command returns directly, actual scaling of the service may take
78
+though the command returns immediately, actual scaling of the service may take
79 79
 some time. The `REPLICAS` column shows both the *actual* and *desired* number
80
-of tasks for the service.
80
+of replica tasks for the service.
81 81
 
82
-In the following example, the desired number of tasks is set to `5`, but the
83
-*actual* number is `3`
82
+In the following example the desired state is  `5` replicas, but the current
83
+number of `RUNNING` tasks is `3`:
84 84
 
85 85
 ```bash
86 86
 $ docker service ls
... ...
@@ -88,8 +88,8 @@ ID            NAME    REPLICAS  IMAGE        COMMAND
88 88
 4cdgfyky7ozw  redis   3/5       redis:3.0.7
89 89
 ```
90 90
 
91
-Once all the tasks are created, the actual number of tasks is equal to the
92
-desired number:
91
+Once all the tasks are created and `RUNNING`, the actual number of tasks is
92
+equal to the desired number:
93 93
 
94 94
 ```bash
95 95
 $ docker service ls
... ...
@@ -97,10 +97,8 @@ ID            NAME    REPLICAS  IMAGE        COMMAND
97 97
 4cdgfyky7ozw  redis   5/5       redis:3.0.7
98 98
 ```
99 99
 
100
-
101 100
 ### Create a service with a rolling update policy
102 101
 
103
-
104 102
 ```bash
105 103
 $ docker service create \
106 104
   --replicas 10 \
... ...
@@ -110,10 +108,12 @@ $ docker service create \
110 110
   redis:3.0.6
111 111
 ```
112 112
 
113
-When this service is [updated](service_update.md), a rolling update will update
114
-tasks in batches of `2`, with `10s` between batches.
113
+When you run a [service update](service_update.md), the scheduler updates a
114
+maximum of 2 tasks at a time, with `10s` between updates. For more information,
115
+refer to the [rolling updates
116
+tutorial](../../swarm/swarm-tutorial/rolling-update.md).
115 117
 
116
-### Setting environment variables (-e --env)
118
+### Set environment variables (-e, --env)
117 119
 
118 120
 This sets environmental variables for all tasks in a service. For example:
119 121
 
... ...
@@ -121,7 +121,7 @@ This sets environmental variables for all tasks in a service. For example:
121 121
 $ docker service create --name redis_2 --replicas 5 --env MYVAR=foo redis:3.0.6
122 122
 ```
123 123
 
124
-### Set metadata on a service (-l --label)
124
+### Set metadata on a service (-l, --label)
125 125
 
126 126
 A label is a `key=value` pair that applies metadata to a service. To label a
127 127
 service with two labels:
... ...
@@ -137,19 +137,22 @@ $ docker service create \
137 137
 For more information about labels, refer to [apply custom
138 138
 metadata](../../userguide/labels-custom-metadata.md).
139 139
 
140
-### Set service mode
140
+### Set service mode (--mode)
141 141
 
142
-You can set the service mode to "replicated" (default) or to "global". A 
143
-replicated  service runs  as many tasks as specified, while a global service 
144
-runs on each  active node in the swarm.
142
+You can set the service mode to "replicated" (default) or to "global". A
143
+replicated  service runs the number of replica tasks you specify. A global
144
+service runs on each active node in the swarm.
145 145
 
146 146
 The following command creates a "global" service:
147 147
 
148 148
 ```bash
149
-$ docker service create --name redis_2 --mode global redis:3.0.6
149
+$ docker service create \
150
+ --name redis_2 \
151
+ --mode global \
152
+ redis:3.0.6
150 153
 ```
151 154
 
152
-### Specify service constraints
155
+### Specify service constraints (--constraint)
153 156
 
154 157
 You can limit the set of nodes where a task can be scheduled by defining
155 158
 constraint expressions. Multiple constraints find nodes that satisfy every
... ...
@@ -178,45 +181,57 @@ $ docker service create \
178 178
   redis:3.0.6
179 179
 ```
180 180
 
181
-### Container networking
182
-The containers provisioned in docker swarm mode can be accessed in service discovery either via a Virtual IP (VIP) and routed through the docker swarm ingress overlay network. Or via a DNS round robbin (DNSRR). This configuration is set using the `--endpoint-mode [vip|dnsrr]` setting. Note that dnsrr is incompatible with `--published` ports.
181
+### Attach a service to an existing network (--network)
183 182
 
184
-### Service discovery
183
+You can use overlay networks to connect one or more services within the swarm.
185 184
 
186
-Discovering other service from within a container can be ac hived via DNS lookup, but you will get different results depending on whether you want the actual service IPs, or the VIP's.
185
+First, create an overlay network on a manager node the docker network create
186
+command:
187 187
 
188
+```bash
189
+$ docker network create --driver overlay my-network
190
+
191
+etjpu59cykrptrgw0z0hk5snf
188 192
 ```
189
-~> nslookup service
190 193
 
191
-Address: 10.255.0.7           # this is the VIP on the ingress network
194
+After you create an overlay network in swarm mode, all manager nodes have
195
+access to the network.
196
+
197
+When you create a service and pass the --network flag to attach the service to
198
+the overlay network:
192 199
 
193
-~> nslookup tasks.service
200
+$ docker service create \
201
+  --replicas 3 \
202
+  --network my-network \
203
+  --name my-web \
204
+  nginx
205
+
206
+716thylsndqma81j6kkkb5aus
207
+The swarm extends my-network to each node running the service.
194 208
 
195
-Non-authoritative answer:
196
-Name:	tasks.service
197
-Address: 10.255.0.26          # this is the real IP of a service on the ingress network
198
-Name:	tasks.service
199
-Address: 10.255.0.27
200
-Name:	tasks.service
201
-Address: 10.255.0.24
209
+Containers on the same network can access each other using
210
+[service discovery](../../swarm/networking.md#use-swarm-mode-service-discovery).
202 211
 
203
-~> nslookup tasks.service.your_net
212
+### Publish service ports externally to the swarm (-p, --publish)
204 213
 
205
-Name:	tasks.service.your_net
206
-Address: 10.0.0.29            # service 1 IP on your net
207
-Name:	tasks.service.your_net
208
-Address: 10.0.0.26            # service 2 IP on your net
209
-Name:	tasks.service.your_net
210
-Address: 10.0.0.28            # service 3 IP on your net
214
+You can publish service ports to make them available externally to the swarm
215
+using the `--publish` flag:
211 216
 
217
+```bash
218
+docker service create --publish <TARGET-PORT>:<SERVICE-PORT> nginx
219
+```
212 220
 
213
-~> nslookup service.your_net      
221
+For example:
214 222
 
215
-Non-authoritative answer:
216
-Name:	service.your_net
217
-Address: 10.0.0.25            # VIP on your net
223
+```bash
224
+docker service create --name my_web --replicas 3 --publish 8080:80 nginx
218 225
 ```
219 226
 
227
+When you publish a service port, the swarm routing mesh makes the service
228
+accessible at the target port on every node regardless if there is a task for
229
+the service running on the node. For more information refer to
230
+[Use swarm mode routing mesh](../../swarm/ingress.md).
231
+
220 232
 ## Related information
221 233
 
222 234
 * [service inspect](service_inspect.md)