github.com/brahmaroutu/docker@v1.2.1-0.20160809185609-eb28dde01f16/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 [menu.main] 7 parent = "smn_cli" 8 +++ 9 <![end-metadata]--> 10 11 # service create 12 13 ```Markdown 14 Usage: docker service create [OPTIONS] IMAGE [COMMAND] [ARG...] 15 16 Create a new service 17 18 Options: 19 --constraint value Placement constraints (default []) 20 --container-label value Service container labels (default []) 21 --endpoint-mode string Endpoint mode (vip or 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 --log-driver string Logging driver for service 28 --log-opt value Logging driver options (default []) 29 --mode string Service mode (replicated or global) (default "replicated") 30 --mount value Attach a mount to the service 31 --name string Service name 32 --network value Network attachments (default []) 33 -p, --publish value Publish a port as a node port (default []) 34 --replicas value Number of tasks (default none) 35 --reserve-cpu value Reserve CPUs (default 0.000) 36 --reserve-memory value Reserve Memory (default 0 B) 37 --restart-condition string Restart when condition is met (none, on-failure, or any) 38 --restart-delay value Delay between restart attempts (default none) 39 --restart-max-attempts value Maximum number of restarts before giving up (default none) 40 --restart-window value Window used to evaluate the restart policy (default none) 41 --stop-grace-period value Time to wait before force killing a container (default none) 42 --update-delay duration Delay between updates 43 --update-failure-action string Action on update failure (pause|continue) (default "pause") 44 --update-parallelism uint Maximum number of tasks updated simultaneously (0 to update all at once) (default 1) 45 -u, --user string Username or UID (format: <name|uid>[:<group|gid>]) 46 --with-registry-auth Send registry authentication details to Swarm agents 47 -w, --workdir string Working directory inside the container 48 ``` 49 50 Creates a service as described by the specified parameters. This command has to 51 be run targeting a manager node. 52 53 ## Examples 54 55 ### Create a service 56 57 ```bash 58 $ docker service create --name redis redis:3.0.6 59 dmu1ept4cxcfe8k8lhtux3ro3 60 61 $ docker service ls 62 ID NAME REPLICAS IMAGE COMMAND 63 dmu1ept4cxcf redis 1/1 redis:3.0.6 64 ``` 65 66 ### Create a service with 5 tasks 67 68 You can set the number of tasks for a service using the `--replicas` option. The 69 following command creates a `redis` service with `5` tasks: 70 71 ```bash 72 $ docker service create --name redis --replicas=5 redis:3.0.6 73 4cdgfyky7ozwh3htjfw0d12qv 74 ``` 75 76 The above command sets the *desired* number of tasks for the service. Even 77 though the command returns directly, actual scaling of the service may take 78 some time. The `REPLICAS` column shows both the *actual* and *desired* number 79 of tasks for the service. 80 81 In the following example, the desired number of tasks is set to `5`, but the 82 *actual* number is `3` 83 84 ```bash 85 $ docker service ls 86 ID NAME REPLICAS IMAGE COMMAND 87 4cdgfyky7ozw redis 3/5 redis:3.0.7 88 ``` 89 90 Once all the tasks are created, the actual number of tasks is equal to the 91 desired number: 92 93 ```bash 94 $ docker service ls 95 ID NAME REPLICAS IMAGE COMMAND 96 4cdgfyky7ozw redis 5/5 redis:3.0.7 97 ``` 98 99 100 ### Create a service with a rolling update policy 101 102 103 ```bash 104 $ docker service create \ 105 --replicas 10 \ 106 --name redis \ 107 --update-delay 10s \ 108 --update-parallelism 2 \ 109 redis:3.0.6 110 ``` 111 112 When this service is [updated](service_update.md), a rolling update will update 113 tasks in batches of `2`, with `10s` between batches. 114 115 ### Setting environment variables (-e --env) 116 117 This sets environmental variables for all tasks in a service. For example: 118 119 ```bash 120 $ docker service create --name redis_2 --replicas 5 --env MYVAR=foo redis:3.0.6 121 ``` 122 123 ### Set metadata on a service (-l --label) 124 125 A label is a `key=value` pair that applies metadata to a service. To label a 126 service with two labels: 127 128 ```bash 129 $ docker service create \ 130 --name redis_2 \ 131 --label com.example.foo="bar" 132 --label bar=baz \ 133 redis:3.0.6 134 ``` 135 136 For more information about labels, refer to [apply custom 137 metadata](../../userguide/labels-custom-metadata.md). 138 139 ### Set service mode 140 141 Is this a replicated service or a global service. A replicated service runs as 142 many tasks as specified, while a global service runs on each active node in the 143 swarm. 144 145 The following command creates a "global" service: 146 147 ```bash 148 $ docker service create --name redis_2 --mode global redis:3.0.6 149 ``` 150 151 ### Specify service constraints 152 153 You can limit the set of nodes where a task can be scheduled by defining 154 constraint expressions. Multiple constraints find nodes that satisfy every 155 expression (AND match). Constraints can match node or Docker Engine labels as 156 follows: 157 158 | node attribute | matches | example | 159 |:------------- |:-------------| :---------------------------------------------| 160 | node.id | node ID | `node.id == 2ivku8v2gvtg4` | 161 | node.hostname | node hostname | `node.hostname != node-2` | 162 | node.role | node role: manager | `node.role == manager` | 163 | node.labels | user defined node labels | `node.labels.security == high` | 164 | engine.labels | Docker Engine's labels | `engine.labels.operatingsystem == ubuntu 14.04`| 165 166 `engine.labels` apply to Docker Engine labels like operating system, 167 drivers, etc. Swarm administrators add `node.labels` for operational purposes by 168 using the [`docker node update`](node_update.md) command. 169 170 For example, the following limits tasks for the redis service to nodes where the 171 node type label equals queue: 172 173 ```bash 174 $ docker service create \ 175 --name redis_2 \ 176 --constraint 'node.labels.type == queue' \ 177 redis:3.0.6 178 ``` 179 180 ## Related information 181 182 * [service inspect](service_inspect.md) 183 * [service ls](service_ls.md) 184 * [service rm](service_rm.md) 185 * [service scale](service_scale.md) 186 * [service ps](service_ps.md) 187 * [service update](service_update.md)