github.com/noxiouz/docker@v0.7.3-0.20160629055221-3d231c78e8c5/docs/reference/commandline/service_create.md (about) 1 <!--[metadata]> 2 +++ 3 title = "service create" 4 description = "The service create command description and usage" 5 keywords = ["service, create"] 6 advisory = "rc" 7 [menu.main] 8 parent = "smn_cli" 9 +++ 10 <![end-metadata]--> 11 12 # service create 13 14 ```Markdown 15 Usage: docker service create [OPTIONS] IMAGE [COMMAND] [ARG...] 16 17 Create a new service 18 19 Options: 20 --constraint value Placement constraints (default []) 21 --endpoint-mode string Endpoint mode(Valid values: VIP, DNSRR) 22 -e, --env value Set environment variables (default []) 23 --help Print usage 24 -l, --label value Service labels (default []) 25 --limit-cpu value Limit CPUs (default 0.000) 26 --limit-memory value Limit Memory (default 0 B) 27 --mode string Service mode (replicated or global) (default "replicated") 28 -m, --mount value Attach a mount to the service 29 --name string Service name 30 --network value Network attachments (default []) 31 -p, --publish value Publish a port as a node port (default []) 32 --replicas value Number of tasks (default none) 33 --reserve-cpu value Reserve CPUs (default 0.000) 34 --reserve-memory value Reserve Memory (default 0 B) 35 --restart-condition string Restart when condition is met (none, on_failure, or any) 36 --restart-delay value Delay between restart attempts (default none) 37 --restart-max-attempts value Maximum number of restarts before giving up (default none) 38 --restart-window value Window used to evaluate the restart policy (default none) 39 --stop-grace-period value Time to wait before force killing a container (default none) 40 --update-delay duration Delay between updates 41 --update-parallelism uint Maximum number of tasks updated simultaneously 42 -u, --user string Username or UID 43 -w, --workdir string Working directory inside the container 44 ``` 45 46 Creates a service as described by the specified parameters. This command has to 47 be run targeting a manager node. 48 49 ## Examples 50 51 ### Create a service 52 53 ```bash 54 $ docker service create --name redis redis:3.0.6 55 dmu1ept4cxcfe8k8lhtux3ro3 56 57 $ docker service ls 58 ID NAME REPLICAS IMAGE COMMAND 59 dmu1ept4cxcf redis 1/1 redis:3.0.6 60 ``` 61 62 ### Create a service with 5 tasks 63 64 You can set the number of tasks for a service using the `--replicas` option. The 65 following command creates a `redis` service with `5` tasks: 66 67 ```bash 68 $ docker service create --name redis --replicas=5 redis:3.0.6 69 4cdgfyky7ozwh3htjfw0d12qv 70 ``` 71 72 The above command sets the *desired* number of tasks for the service. Even 73 though the command returns directly, actual scaling of the service may take 74 some time. The `REPLICAS` column shows both the *actual* and *desired* number 75 of tasks for the service. 76 77 In the following example, the desired number of tasks is set to `5`, but the 78 *actual* number is `3` 79 80 ```bash 81 $ docker service ls 82 ID NAME REPLICAS IMAGE COMMAND 83 4cdgfyky7ozw redis 3/5 redis:3.0.7 84 ``` 85 86 Once all the tasks are created, the actual number of tasks is equal to the 87 desired number: 88 89 ```bash 90 $ docker service ls 91 ID NAME REPLICAS IMAGE COMMAND 92 4cdgfyky7ozw redis 5/5 redis:3.0.7 93 ``` 94 95 96 ### Create a service with a rolling update constraints 97 98 99 ```bash 100 $ docker service create \ 101 --replicas 10 \ 102 --name redis \ 103 --update-delay 10s \ 104 --update-parallelism 2 \ 105 redis:3.0.6 106 ``` 107 108 When this service is [updated](service_update.md), a rolling update will update 109 tasks in batches of `2`, with `10s` between batches. 110 111 ### Setting environment variables (-e --env) 112 113 This sets environmental variables for all tasks in a service. For example: 114 115 ```bash 116 $ docker service create --name redis_2 --replicas 5 --env MYVAR=foo redis:3.0.6 117 ``` 118 119 ### Set metadata on a service (-l --label) 120 121 A label is a `key=value` pair that applies metadata to a service. To label a 122 service with two labels: 123 124 ```bash 125 $ docker service create \ 126 --name redis_2 \ 127 --label com.example.foo="bar" 128 --label bar=baz \ 129 redis:3.0.6 130 ``` 131 132 For more information about labels, refer to [apply custom 133 metadata](../../userguide/labels-custom-metadata.md) 134 135 ### Service mode 136 137 Is this a replicated service or a global service. A replicated service runs as 138 many tasks as specified, while a global service runs on each active node in the 139 swarm. 140 141 The following command creates a "global" service: 142 143 ```bash 144 $ docker service create --name redis_2 --mode global redis:3.0.6 145 ``` 146 147 148 ## Related information 149 150 * [service inspect](service_inspect.md) 151 * [service ls](service_ls.md) 152 * [service rm](service_rm.md) 153 * [service scale](service_scale.md) 154 * [service tasks](service_tasks.md) 155 * [service update](service_update.md)