mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
carries and closes 25414
Signed-off-by: Charles Smith <charles.smith@docker.com>
This commit is contained in:
parent
21a9c64b77
commit
e7e85c7e06
1 changed files with 63 additions and 48 deletions
|
@ -48,8 +48,8 @@ Options:
|
||||||
-w, --workdir string Working directory inside the container
|
-w, --workdir string Working directory inside the container
|
||||||
```
|
```
|
||||||
|
|
||||||
Creates a service as described by the specified parameters. This command has to
|
Creates a service as described by the specified parameters. You must run this
|
||||||
be run targeting a manager node.
|
command on a manager node.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
@ -64,10 +64,10 @@ ID NAME REPLICAS IMAGE COMMAND
|
||||||
dmu1ept4cxcf redis 1/1 redis:3.0.6
|
dmu1ept4cxcf redis 1/1 redis:3.0.6
|
||||||
```
|
```
|
||||||
|
|
||||||
### Create a service with 5 tasks
|
### Create a service with 5 replica tasks (--replicas)
|
||||||
|
|
||||||
You can set the number of tasks for a service using the `--replicas` option. The
|
Use the `--replicas` flag to set the number of replica tasks for a replicated
|
||||||
following command creates a `redis` service with `5` tasks:
|
service. The following command creates a `redis` service with `5` replica tasks:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ docker service create --name redis --replicas=5 redis:3.0.6
|
$ 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
|
||||||
```
|
```
|
||||||
|
|
||||||
The above command sets the *desired* number of tasks for the service. Even
|
The above command sets the *desired* number of tasks for the service. Even
|
||||||
though the command returns directly, actual scaling of the service may take
|
though the command returns immediately, actual scaling of the service may take
|
||||||
some time. The `REPLICAS` column shows both the *actual* and *desired* number
|
some time. The `REPLICAS` column shows both the *actual* and *desired* number
|
||||||
of tasks for the service.
|
of replica tasks for the service.
|
||||||
|
|
||||||
In the following example, the desired number of tasks is set to `5`, but the
|
In the following example the desired state is `5` replicas, but the current
|
||||||
*actual* number is `3`
|
number of `RUNNING` tasks is `3`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ docker service ls
|
$ docker service ls
|
||||||
|
@ -88,8 +88,8 @@ ID NAME REPLICAS IMAGE COMMAND
|
||||||
4cdgfyky7ozw redis 3/5 redis:3.0.7
|
4cdgfyky7ozw redis 3/5 redis:3.0.7
|
||||||
```
|
```
|
||||||
|
|
||||||
Once all the tasks are created, the actual number of tasks is equal to the
|
Once all the tasks are created and `RUNNING`, the actual number of tasks is
|
||||||
desired number:
|
equal to the desired number:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ docker service ls
|
$ docker service ls
|
||||||
|
@ -97,10 +97,8 @@ ID NAME REPLICAS IMAGE COMMAND
|
||||||
4cdgfyky7ozw redis 5/5 redis:3.0.7
|
4cdgfyky7ozw redis 5/5 redis:3.0.7
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### Create a service with a rolling update policy
|
### Create a service with a rolling update policy
|
||||||
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ docker service create \
|
$ docker service create \
|
||||||
--replicas 10 \
|
--replicas 10 \
|
||||||
|
@ -110,10 +108,12 @@ $ docker service create \
|
||||||
redis:3.0.6
|
redis:3.0.6
|
||||||
```
|
```
|
||||||
|
|
||||||
When this service is [updated](service_update.md), a rolling update will update
|
When you run a [service update](service_update.md), the scheduler updates a
|
||||||
tasks in batches of `2`, with `10s` between batches.
|
maximum of 2 tasks at a time, with `10s` between updates. For more information,
|
||||||
|
refer to the [rolling updates
|
||||||
|
tutorial](../../swarm/swarm-tutorial/rolling-update.md).
|
||||||
|
|
||||||
### Setting environment variables (-e --env)
|
### Set environment variables (-e, --env)
|
||||||
|
|
||||||
This sets environmental variables for all tasks in a service. For example:
|
This sets environmental variables for all tasks in a service. For example:
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ This sets environmental variables for all tasks in a service. For example:
|
||||||
$ docker service create --name redis_2 --replicas 5 --env MYVAR=foo redis:3.0.6
|
$ docker service create --name redis_2 --replicas 5 --env MYVAR=foo redis:3.0.6
|
||||||
```
|
```
|
||||||
|
|
||||||
### Set metadata on a service (-l --label)
|
### Set metadata on a service (-l, --label)
|
||||||
|
|
||||||
A label is a `key=value` pair that applies metadata to a service. To label a
|
A label is a `key=value` pair that applies metadata to a service. To label a
|
||||||
service with two labels:
|
service with two labels:
|
||||||
|
@ -137,19 +137,22 @@ $ docker service create \
|
||||||
For more information about labels, refer to [apply custom
|
For more information about labels, refer to [apply custom
|
||||||
metadata](../../userguide/labels-custom-metadata.md).
|
metadata](../../userguide/labels-custom-metadata.md).
|
||||||
|
|
||||||
### Set service mode
|
### Set service mode (--mode)
|
||||||
|
|
||||||
You can set the service mode to "replicated" (default) or to "global". A
|
You can set the service mode to "replicated" (default) or to "global". A
|
||||||
replicated service runs as many tasks as specified, while a global service
|
replicated service runs the number of replica tasks you specify. A global
|
||||||
runs on each active node in the swarm.
|
service runs on each active node in the swarm.
|
||||||
|
|
||||||
The following command creates a "global" service:
|
The following command creates a "global" service:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ docker service create --name redis_2 --mode global redis:3.0.6
|
$ docker service create \
|
||||||
|
--name redis_2 \
|
||||||
|
--mode global \
|
||||||
|
redis:3.0.6
|
||||||
```
|
```
|
||||||
|
|
||||||
### Specify service constraints
|
### Specify service constraints (--constraint)
|
||||||
|
|
||||||
You can limit the set of nodes where a task can be scheduled by defining
|
You can limit the set of nodes where a task can be scheduled by defining
|
||||||
constraint expressions. Multiple constraints find nodes that satisfy every
|
constraint expressions. Multiple constraints find nodes that satisfy every
|
||||||
|
@ -178,45 +181,57 @@ $ docker service create \
|
||||||
redis:3.0.6
|
redis:3.0.6
|
||||||
```
|
```
|
||||||
|
|
||||||
### Container networking
|
### Attach a service to an existing network (--network)
|
||||||
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.
|
|
||||||
|
|
||||||
### Service discovery
|
You can use overlay networks to connect one or more services within the swarm.
|
||||||
|
|
||||||
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.
|
First, create an overlay network on a manager node the docker network create
|
||||||
|
command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ docker network create --driver overlay my-network
|
||||||
|
|
||||||
|
etjpu59cykrptrgw0z0hk5snf
|
||||||
```
|
```
|
||||||
~> nslookup service
|
|
||||||
|
|
||||||
Address: 10.255.0.7 # this is the VIP on the ingress network
|
After you create an overlay network in swarm mode, all manager nodes have
|
||||||
|
access to the network.
|
||||||
|
|
||||||
~> nslookup tasks.service
|
When you create a service and pass the --network flag to attach the service to
|
||||||
|
the overlay network:
|
||||||
|
|
||||||
Non-authoritative answer:
|
$ docker service create \
|
||||||
Name: tasks.service
|
--replicas 3 \
|
||||||
Address: 10.255.0.26 # this is the real IP of a service on the ingress network
|
--network my-network \
|
||||||
Name: tasks.service
|
--name my-web \
|
||||||
Address: 10.255.0.27
|
nginx
|
||||||
Name: tasks.service
|
|
||||||
Address: 10.255.0.24
|
|
||||||
|
|
||||||
~> nslookup tasks.service.your_net
|
716thylsndqma81j6kkkb5aus
|
||||||
|
The swarm extends my-network to each node running the service.
|
||||||
|
|
||||||
Name: tasks.service.your_net
|
Containers on the same network can access each other using
|
||||||
Address: 10.0.0.29 # service 1 IP on your net
|
[service discovery](../../swarm/networking.md#use-swarm-mode-service-discovery).
|
||||||
Name: tasks.service.your_net
|
|
||||||
Address: 10.0.0.26 # service 2 IP on your net
|
|
||||||
Name: tasks.service.your_net
|
|
||||||
Address: 10.0.0.28 # service 3 IP on your net
|
|
||||||
|
|
||||||
|
### Publish service ports externally to the swarm (-p, --publish)
|
||||||
|
|
||||||
~> nslookup service.your_net
|
You can publish service ports to make them available externally to the swarm
|
||||||
|
using the `--publish` flag:
|
||||||
|
|
||||||
Non-authoritative answer:
|
```bash
|
||||||
Name: service.your_net
|
docker service create --publish <TARGET-PORT>:<SERVICE-PORT> nginx
|
||||||
Address: 10.0.0.25 # VIP on your net
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker service create --name my_web --replicas 3 --publish 8080:80 nginx
|
||||||
|
```
|
||||||
|
|
||||||
|
When you publish a service port, the swarm routing mesh makes the service
|
||||||
|
accessible at the target port on every node regardless if there is a task for
|
||||||
|
the service running on the node. For more information refer to
|
||||||
|
[Use swarm mode routing mesh](../../swarm/ingress.md).
|
||||||
|
|
||||||
## Related information
|
## Related information
|
||||||
|
|
||||||
* [service inspect](service_inspect.md)
|
* [service inspect](service_inspect.md)
|
||||||
|
|
Loading…
Reference in a new issue