github.com/khulnasoft/cli@v0.0.0-20240402070845-01bcad7beefa/docs/reference/commandline/service_create.md (about)

     1  # service create
     2  
     3  <!---MARKER_GEN_START-->
     4  Create a new service
     5  
     6  ### Options
     7  
     8  | Name                                                | Type              | Default      | Description                                                                                         |
     9  |:----------------------------------------------------|:------------------|:-------------|:----------------------------------------------------------------------------------------------------|
    10  | `--cap-add`                                         | `list`            |              | Add Linux capabilities                                                                              |
    11  | `--cap-drop`                                        | `list`            |              | Drop Linux capabilities                                                                             |
    12  | [`--config`](#config)                               | `config`          |              | Specify configurations to expose to the service                                                     |
    13  | [`--constraint`](#constraint)                       | `list`            |              | Placement constraints                                                                               |
    14  | `--container-label`                                 | `list`            |              | Container labels                                                                                    |
    15  | `--credential-spec`                                 | `credential-spec` |              | Credential spec for managed service account (Windows only)                                          |
    16  | `-d`, `--detach`                                    |                   |              | Exit immediately instead of waiting for the service to converge                                     |
    17  | `--dns`                                             | `list`            |              | Set custom DNS servers                                                                              |
    18  | `--dns-option`                                      | `list`            |              | Set DNS options                                                                                     |
    19  | `--dns-search`                                      | `list`            |              | Set custom DNS search domains                                                                       |
    20  | `--endpoint-mode`                                   | `string`          | `vip`        | Endpoint mode (vip or dnsrr)                                                                        |
    21  | `--entrypoint`                                      | `command`         |              | Overwrite the default ENTRYPOINT of the image                                                       |
    22  | [`-e`](#env), [`--env`](#env)                       | `list`            |              | Set environment variables                                                                           |
    23  | `--env-file`                                        | `list`            |              | Read in a file of environment variables                                                             |
    24  | `--generic-resource`                                | `list`            |              | User defined resources                                                                              |
    25  | `--group`                                           | `list`            |              | Set one or more supplementary user groups for the container                                         |
    26  | `--health-cmd`                                      | `string`          |              | Command to run to check health                                                                      |
    27  | `--health-interval`                                 | `duration`        |              | Time between running the check (ms\|s\|m\|h)                                                        |
    28  | `--health-retries`                                  | `int`             | `0`          | Consecutive failures needed to report unhealthy                                                     |
    29  | `--health-start-interval`                           | `duration`        |              | Time between running the check during the start period (ms\|s\|m\|h)                                |
    30  | `--health-start-period`                             | `duration`        |              | Start period for the container to initialize before counting retries towards unstable (ms\|s\|m\|h) |
    31  | `--health-timeout`                                  | `duration`        |              | Maximum time to allow one check to run (ms\|s\|m\|h)                                                |
    32  | `--host`                                            | `list`            |              | Set one or more custom host-to-IP mappings (host:ip)                                                |
    33  | [`--hostname`](#hostname)                           | `string`          |              | Container hostname                                                                                  |
    34  | `--init`                                            |                   |              | Use an init inside each service container to forward signals and reap processes                     |
    35  | [`--isolation`](#isolation)                         | `string`          |              | Service container isolation mode                                                                    |
    36  | [`-l`](#label), [`--label`](#label)                 | `list`            |              | Service labels                                                                                      |
    37  | `--limit-cpu`                                       | `decimal`         |              | Limit CPUs                                                                                          |
    38  | `--limit-memory`                                    | `bytes`           | `0`          | Limit Memory                                                                                        |
    39  | `--limit-pids`                                      | `int64`           | `0`          | Limit maximum number of processes (default 0 = unlimited)                                           |
    40  | `--log-driver`                                      | `string`          |              | Logging driver for service                                                                          |
    41  | `--log-opt`                                         | `list`            |              | Logging driver options                                                                              |
    42  | `--max-concurrent`                                  | `uint`            |              | Number of job tasks to run concurrently (default equal to --replicas)                               |
    43  | `--mode`                                            | `string`          | `replicated` | Service mode (`replicated`, `global`, `replicated-job`, `global-job`)                               |
    44  | [`--mount`](#mount)                                 | `mount`           |              | Attach a filesystem mount to the service                                                            |
    45  | `--name`                                            | `string`          |              | Service name                                                                                        |
    46  | [`--network`](#network)                             | `network`         |              | Network attachments                                                                                 |
    47  | `--no-healthcheck`                                  |                   |              | Disable any container-specified HEALTHCHECK                                                         |
    48  | `--no-resolve-image`                                |                   |              | Do not query the registry to resolve image digest and supported platforms                           |
    49  | [`--placement-pref`](#placement-pref)               | `pref`            |              | Add a placement preference                                                                          |
    50  | [`-p`](#publish), [`--publish`](#publish)           | `port`            |              | Publish a port as a node port                                                                       |
    51  | `-q`, `--quiet`                                     |                   |              | Suppress progress output                                                                            |
    52  | `--read-only`                                       |                   |              | Mount the container's root filesystem as read only                                                  |
    53  | [`--replicas`](#replicas)                           | `uint`            |              | Number of tasks                                                                                     |
    54  | [`--replicas-max-per-node`](#replicas-max-per-node) | `uint64`          | `0`          | Maximum number of tasks per node (default 0 = unlimited)                                            |
    55  | `--reserve-cpu`                                     | `decimal`         |              | Reserve CPUs                                                                                        |
    56  | [`--reserve-memory`](#reserve-memory)               | `bytes`           | `0`          | Reserve Memory                                                                                      |
    57  | `--restart-condition`                               | `string`          |              | Restart when condition is met (`none`, `on-failure`, `any`) (default `any`)                         |
    58  | `--restart-delay`                                   | `duration`        |              | Delay between restart attempts (ns\|us\|ms\|s\|m\|h) (default 5s)                                   |
    59  | `--restart-max-attempts`                            | `uint`            |              | Maximum number of restarts before giving up                                                         |
    60  | `--restart-window`                                  | `duration`        |              | Window used to evaluate the restart policy (ns\|us\|ms\|s\|m\|h)                                    |
    61  | `--rollback-delay`                                  | `duration`        | `0s`         | Delay between task rollbacks (ns\|us\|ms\|s\|m\|h) (default 0s)                                     |
    62  | `--rollback-failure-action`                         | `string`          |              | Action on rollback failure (`pause`, `continue`) (default `pause`)                                  |
    63  | `--rollback-max-failure-ratio`                      | `float`           | `0`          | Failure rate to tolerate during a rollback (default 0)                                              |
    64  | `--rollback-monitor`                                | `duration`        | `0s`         | Duration after each task rollback to monitor for failure (ns\|us\|ms\|s\|m\|h) (default 5s)         |
    65  | `--rollback-order`                                  | `string`          |              | Rollback order (`start-first`, `stop-first`) (default `stop-first`)                                 |
    66  | `--rollback-parallelism`                            | `uint64`          | `1`          | Maximum number of tasks rolled back simultaneously (0 to roll back all at once)                     |
    67  | [`--secret`](#secret)                               | `secret`          |              | Specify secrets to expose to the service                                                            |
    68  | `--stop-grace-period`                               | `duration`        |              | Time to wait before force killing a container (ns\|us\|ms\|s\|m\|h) (default 10s)                   |
    69  | `--stop-signal`                                     | `string`          |              | Signal to stop the container                                                                        |
    70  | `--sysctl`                                          | `list`            |              | Sysctl options                                                                                      |
    71  | `-t`, `--tty`                                       |                   |              | Allocate a pseudo-TTY                                                                               |
    72  | `--ulimit`                                          | `ulimit`          |              | Ulimit options                                                                                      |
    73  | [`--update-delay`](#update-delay)                   | `duration`        | `0s`         | Delay between updates (ns\|us\|ms\|s\|m\|h) (default 0s)                                            |
    74  | `--update-failure-action`                           | `string`          |              | Action on update failure (`pause`, `continue`, `rollback`) (default `pause`)                        |
    75  | `--update-max-failure-ratio`                        | `float`           | `0`          | Failure rate to tolerate during an update (default 0)                                               |
    76  | `--update-monitor`                                  | `duration`        | `0s`         | Duration after each task update to monitor for failure (ns\|us\|ms\|s\|m\|h) (default 5s)           |
    77  | `--update-order`                                    | `string`          |              | Update order (`start-first`, `stop-first`) (default `stop-first`)                                   |
    78  | `--update-parallelism`                              | `uint64`          | `1`          | Maximum number of tasks updated simultaneously (0 to update all at once)                            |
    79  | `-u`, `--user`                                      | `string`          |              | Username or UID (format: <name\|uid>[:<group\|gid>])                                                |
    80  | [`--with-registry-auth`](#with-registry-auth)       |                   |              | Send registry authentication details to swarm agents                                                |
    81  | `-w`, `--workdir`                                   | `string`          |              | Working directory inside the container                                                              |
    82  
    83  
    84  <!---MARKER_GEN_END-->
    85  
    86  ## Description
    87  
    88  Creates a service as described by the specified parameters.
    89  
    90  > **Note**
    91  >
    92  > This is a cluster management command, and must be executed on a swarm
    93  > manager node. To learn about managers and workers, refer to the
    94  > [Swarm mode section](https://docs.docker.com/engine/swarm/) in the
    95  > documentation.
    96  
    97  ## Examples
    98  
    99  ### Create a service
   100  
   101  ```console
   102  $ docker service create --name redis redis:3.0.6
   103  
   104  dmu1ept4cxcfe8k8lhtux3ro3
   105  
   106  $ docker service create --mode global --name redis2 redis:3.0.6
   107  
   108  a8q9dasaafudfs8q8w32udass
   109  
   110  $ docker service ls
   111  
   112  ID            NAME    MODE        REPLICAS  IMAGE
   113  dmu1ept4cxcf  redis   replicated  1/1       redis:3.0.6
   114  a8q9dasaafud  redis2  global      1/1       redis:3.0.6
   115  ```
   116  
   117  #### <a name="with-registry-auth"></a> Create a service using an image on a private registry (--with-registry-auth)
   118  
   119  If your image is available on a private registry which requires login, use the
   120  `--with-registry-auth` flag with `docker service create`, after logging in. If
   121  your image is stored on `registry.example.com`, which is a private registry, use
   122  a command like the following:
   123  
   124  ```console
   125  $ docker login registry.example.com
   126  
   127  $ docker service  create \
   128    --with-registry-auth \
   129    --name my_service \
   130    registry.example.com/acme/my_image:latest
   131  ```
   132  
   133  This passes the login token from your local client to the swarm nodes where the
   134  service is deployed, using the encrypted WAL logs. With this information, the
   135  nodes are able to log in to the registry and pull the image.
   136  
   137  ### <a name="replicas"></a> Create a service with 5 replica tasks (--replicas)
   138  
   139  Use the `--replicas` flag to set the number of replica tasks for a replicated
   140  service. The following command creates a `redis` service with `5` replica tasks:
   141  
   142  ```console
   143  $ docker service create --name redis --replicas=5 redis:3.0.6
   144  
   145  4cdgfyky7ozwh3htjfw0d12qv
   146  ```
   147  
   148  The above command sets the *desired* number of tasks for the service. Even
   149  though the command returns immediately, actual scaling of the service may take
   150  some time. The `REPLICAS` column shows both the actual and desired number
   151  of replica tasks for the service.
   152  
   153  In the following example the desired state is  `5` replicas, but the current
   154  number of `RUNNING` tasks is `3`:
   155  
   156  ```console
   157  $ docker service ls
   158  
   159  ID            NAME   MODE        REPLICAS  IMAGE
   160  4cdgfyky7ozw  redis  replicated  3/5       redis:3.0.7
   161  ```
   162  
   163  Once all the tasks are created and `RUNNING`, the actual number of tasks is
   164  equal to the desired number:
   165  
   166  ```console
   167  $ docker service ls
   168  
   169  ID            NAME   MODE        REPLICAS  IMAGE
   170  4cdgfyky7ozw  redis  replicated  5/5       redis:3.0.7
   171  ```
   172  
   173  ### <a name="secret"></a> Create a service with secrets (--secret)
   174  
   175  Use the `--secret` flag to give a container access to a
   176  [secret](secret_create.md).
   177  
   178  Create a service specifying a secret:
   179  
   180  ```console
   181  $ docker service create --name redis --secret secret.json redis:3.0.6
   182  
   183  4cdgfyky7ozwh3htjfw0d12qv
   184  ```
   185  
   186  Create a service specifying the secret, target, user/group ID, and mode:
   187  
   188  ```console
   189  $ docker service create --name redis \
   190      --secret source=ssh-key,target=ssh \
   191      --secret source=app-key,target=app,uid=1000,gid=1001,mode=0400 \
   192      redis:3.0.6
   193  
   194  4cdgfyky7ozwh3htjfw0d12qv
   195  ```
   196  
   197  To grant a service access to multiple secrets, use multiple `--secret` flags.
   198  
   199  Secrets are located in `/run/secrets` in the container if no target is specified.
   200  If no target is specified, the name of the secret is used as the in memory file
   201  in the container. If a target is specified, that is used as the filename. In the
   202  example above, two files are created: `/run/secrets/ssh` and
   203  `/run/secrets/app` for each of the secret targets specified.
   204  
   205  ### <a name="config"></a> Create a service with configs (--config)
   206  
   207  Use the `--config` flag to give a container access to a
   208  [config](config_create.md).
   209  
   210  Create a service with a config. The config will be mounted into `redis-config`,
   211  be owned by the user who runs the command inside the container (often `root`),
   212  and have file mode `0444` or world-readable. You can specify the `uid` and `gid`
   213  as numerical IDs or names. When using names, the provided group/user names must
   214  pre-exist in the container. The `mode` is specified as a 4-number sequence such
   215  as `0755`.
   216  
   217  ```console
   218  $ docker service create --name=redis --config redis-conf redis:3.0.6
   219  ```
   220  
   221  Create a service with a config and specify the target location and file mode:
   222  
   223  ```console
   224  $ docker service create --name redis \
   225    --config source=redis-conf,target=/etc/redis/redis.conf,mode=0400 redis:3.0.6
   226  ```
   227  
   228  To grant a service access to multiple configs, use multiple `--config` flags.
   229  
   230  Configs are located in `/` in the container if no target is specified. If no
   231  target is specified, the name of the config is used as the name of the file in
   232  the container. If a target is specified, that is used as the filename.
   233  
   234  ### <a name="update-delay"></a> Create a service with a rolling update policy
   235  
   236  ```console
   237  $ docker service create \
   238    --replicas 10 \
   239    --name redis \
   240    --update-delay 10s \
   241    --update-parallelism 2 \
   242    redis:3.0.6
   243  ```
   244  
   245  When you run a [service update](service_update.md), the scheduler updates a
   246  maximum of 2 tasks at a time, with `10s` between updates. For more information,
   247  refer to the [rolling updates
   248  tutorial](https://docs.docker.com/engine/swarm/swarm-tutorial/rolling-update/).
   249  
   250  ### <a name="env"></a> Set environment variables (-e, --env)
   251  
   252  This sets an environment variable for all tasks in a service. For example:
   253  
   254  ```console
   255  $ docker service create \
   256    --name redis_2 \
   257    --replicas 5 \
   258    --env MYVAR=foo \
   259    redis:3.0.6
   260  ```
   261  
   262  To specify multiple environment variables, specify multiple `--env` flags, each
   263  with a separate key-value pair.
   264  
   265  ```console
   266  $ docker service create \
   267    --name redis_2 \
   268    --replicas 5 \
   269    --env MYVAR=foo \
   270    --env MYVAR2=bar \
   271    redis:3.0.6
   272  ```
   273  
   274  ### <a name="hostname"></a> Create a service with specific hostname (--hostname)
   275  
   276  This option sets the docker service containers hostname to a specific string.
   277  For example:
   278  
   279  ```console
   280  $ docker service create --name redis --hostname myredis redis:3.0.6
   281  ```
   282  
   283  ### <a name="label"></a> Set metadata on a service (-l, --label)
   284  
   285  A label is a `key=value` pair that applies metadata to a service. To label a
   286  service with two labels:
   287  
   288  ```console
   289  $ docker service create \
   290    --name redis_2 \
   291    --label com.example.foo="bar" \
   292    --label bar=baz \
   293    redis:3.0.6
   294  ```
   295  
   296  For more information about labels, refer to [apply custom
   297  metadata](https://docs.docker.com/config/labels-custom-metadata/).
   298  
   299  ### <a name="mount"></a> Add bind mounts, volumes or memory filesystems (--mount)
   300  
   301  Docker supports three different kinds of mounts, which allow containers to read
   302  from or write to files or directories, either on the host operating system, or
   303  on memory filesystems. These types are data volumes (often referred to simply
   304  as volumes), bind mounts, tmpfs, and named pipes.
   305  
   306  A **bind mount** makes a file or directory on the host available to the
   307  container it is mounted within. A bind mount may be either read-only or
   308  read-write. For example, a container might share its host's DNS information by
   309  means of a bind mount of the host's `/etc/resolv.conf` or a container might
   310  write logs to its host's `/var/log/myContainerLogs` directory. If you use
   311  bind mounts and your host and containers have different notions of permissions,
   312  access controls, or other such details, you will run into portability issues.
   313  
   314  A **named volume** is a mechanism for decoupling persistent data needed by your
   315  container from the image used to create the container and from the host machine.
   316  Named volumes are created and managed by Docker, and a named volume persists
   317  even when no container is currently using it. Data in named volumes can be
   318  shared between a container and the host machine, as well as between multiple
   319  containers. Docker uses a _volume driver_ to create, manage, and mount volumes.
   320  You can back up or restore volumes using Docker commands.
   321  
   322  A **tmpfs** mounts a tmpfs inside a container for volatile data.
   323  
   324  A **npipe** mounts a named pipe from the host into the container.
   325  
   326  Consider a situation where your image starts a lightweight web server. You could
   327  use that image as a base image, copy in your website's HTML files, and package
   328  that into another image. Each time your website changed, you'd need to update
   329  the new image and redeploy all of the containers serving your website. A better
   330  solution is to store the website in a named volume which is attached to each of
   331  your web server containers when they start. To update the website, you just
   332  update the named volume.
   333  
   334  For more information about named volumes, see
   335  [Data Volumes](https://docs.docker.com/storage/volumes/).
   336  
   337  The following table describes options which apply to both bind mounts and named
   338  volumes in a service:
   339  
   340  <table>
   341    <tr>
   342      <th>Option</th>
   343      <th>Required</th>
   344      <th>Description</th>
   345    </tr>
   346    <tr>
   347      <td><b>type</b></td>
   348      <td></td>
   349      <td>
   350        <p>The type of mount, can be either <tt>volume</tt>, <tt>bind</tt>, <tt>tmpfs</tt>, or <tt>npipe</tt>. Defaults to <tt>volume</tt> if no type is specified.</p>
   351        <ul>
   352          <li><tt>volume</tt>: mounts a <a href="https://docs.docker.com/reference/cli/docker/volume/create/">managed volume</a>
   353          into the container.</li> <li><tt>bind</tt>:
   354          bind-mounts a directory or file from the host into the container.</li>
   355          <li><tt>tmpfs</tt>: mount a tmpfs in the container</li>
   356          <li><tt>npipe</tt>: mounts named pipe from the host into the container (Windows containers only).</li>
   357        </ul>
   358      </td>
   359    </tr>
   360    <tr>
   361      <td><b>src</b> or <b>source</b></td>
   362      <td>for <tt>type=bind</tt> and <tt>type=npipe</tt></td>
   363      <td>
   364        <ul>
   365          <li>
   366           <tt>type=volume</tt>: <tt>src</tt> is an optional way to specify the name of the volume (for example, <tt>src=my-volume</tt>).
   367            If the named volume does not exist, it is automatically created. If no <tt>src</tt> is specified, the volume is
   368            assigned a random name which is guaranteed to be unique on the host, but may not be unique cluster-wide.
   369            A randomly-named volume has the same lifecycle as its container and is destroyed when the <i>container</i>
   370            is destroyed (which is upon <tt>service update</tt>, or when scaling or re-balancing the service)
   371          </li>
   372          <li>
   373            <tt>type=bind</tt>: <tt>src</tt> is required, and specifies an absolute path to the file or directory to bind-mount
   374            (for example, <tt>src=/path/on/host/</tt>). An error is produced if the file or directory does not exist.
   375          </li>
   376          <li>
   377            <tt>type=tmpfs</tt>: <tt>src</tt> is not supported.
   378          </li>
   379        </ul>
   380      </td>
   381    </tr>
   382    <tr>
   383      <td><p><b>dst</b> or <b>destination</b> or <b>target</b></p></td>
   384      <td>yes</td>
   385      <td>
   386        <p>Mount path inside the container, for example <tt>/some/path/in/container/</tt>.
   387        If the path does not exist in the container's filesystem, the Engine creates
   388        a directory at the specified location before mounting the volume or bind mount.</p>
   389      </td>
   390    </tr>
   391    <tr>
   392      <td><p><b>readonly</b> or <b>ro</b></p></td>
   393      <td></td>
   394      <td>
   395        <p>The Engine mounts binds and volumes <tt>read-write</tt> unless <tt>readonly</tt> option
   396        is given when mounting the bind or volume. Note that setting <tt>readonly</tt> for a
   397        bind-mount may not make its submounts <tt>readonly</tt> depending on the kernel version. See also <tt>bind-recursive</tt>.</p>
   398        <ul>
   399          <li><tt>true</tt> or <tt>1</tt> or no value: Mounts the bind or volume read-only.</li>
   400          <li><tt>false</tt> or <tt>0</tt>: Mounts the bind or volume read-write.</li>
   401        </ul>
   402      </td>
   403    </tr>
   404  </table>
   405  
   406  #### Options for bind mounts
   407  
   408  The following options can only be used for bind mounts (`type=bind`):
   409  
   410  
   411  <table>
   412    <tr>
   413      <th>Option</th>
   414      <th>Description</th>
   415    </tr>
   416    <tr>
   417      <td><b>bind-propagation</b></td>
   418      <td>
   419        <p>See the <a href="#bind-propagation">bind propagation section</a>.</p>
   420      </td>
   421    </tr>
   422    <tr>
   423      <td><b>consistency</b></td>
   424      <td>
   425        <p>The consistency requirements for the mount; one of </p>
   426        <ul>
   427         <li><tt>default</tt>: Equivalent to <tt>consistent</tt>.</li>
   428         <li><tt>consistent</tt>: Full consistency.  The container runtime and the host maintain an identical view of the mount at all times.</li>
   429         <li><tt>cached</tt>: The host's view of the mount is authoritative.  There may be delays before updates made on the host are visible within a container.</li>
   430         <li><tt>delegated</tt>: The container runtime's view of the mount is authoritative.  There may be delays before updates made in a container are visible on the host.</li>
   431        </ul>
   432      </td>
   433    </tr>
   434    <tr>
   435      <td><b>bind-recursive</b></td>
   436      <td>
   437        By default, submounts are recursively bind-mounted as well. However, this behavior can be confusing when a
   438        bind mount is configured with <tt>readonly</tt> option, because submounts may not be mounted as read-only,
   439        depending on the kernel version.
   440        Set <tt>bind-recursive</tt> to control the behavior of the recursive bind-mount.<br />
   441        <br />
   442        A value is one of:<br />
   443        <br />
   444        <ul>
   445          <li><<tt>enabled</tt>: Enables recursive bind-mount.
   446          Read-only mounts are made recursively read-only if kernel is v5.12 or later.
   447          Otherwise they are not made recursively read-only.</li>
   448          <li><<tt>disabled</tt>: Disables recursive bind-mount.</li>
   449          <li><<tt>writable</tt>: Enables recursive bind-mount.
   450          Read-only mounts are not made recursively read-only.</li>
   451          <li><<tt>readonly</tt>: Enables recursive bind-mount.
   452          Read-only mounts are made recursively read-only if kernel is v5.12 or later.
   453          Otherwise the Engine raises an error.</li>
   454        </ul>
   455        When the option is not specified, the default behavior correponds to setting <tt>enabled</tt>.
   456      </td>
   457    </tr>
   458    <tr>
   459      <td><b>bind-nonrecursive</b></td>
   460      <td>
   461        <tt>bind-nonrecursive</tt> is deprecated since Docker Engine v25.0.
   462        Use <tt>bind-recursive</tt>instead.<br />
   463        <br />
   464        A value is optional:<br />
   465        <br />
   466        <ul>
   467          <li><tt>true</tt> or <tt>1</tt>:  Equivalent to <tt>bind-recursive=disabled</tt>.</li>
   468          <li><tt>false</tt> or <tt>0</tt>: Equivalent to <tt>bind-recursive=enabled</tt>.</li>
   469        </ul>
   470      </td>
   471    </tr>
   472  </table>
   473  
   474  ##### Bind propagation
   475  
   476  Bind propagation refers to whether or not mounts created within a given
   477  bind mount or named volume can be propagated to replicas of that mount. Consider
   478  a mount point `/mnt`, which is also mounted on `/tmp`. The propagation settings
   479  control whether a mount on `/tmp/a` would also be available on `/mnt/a`. Each
   480  propagation setting has a recursive counterpoint. In the case of recursion,
   481  consider that `/tmp/a` is also mounted as `/foo`. The propagation settings
   482  control whether `/mnt/a` and/or `/tmp/a` would exist.
   483  
   484  The `bind-propagation` option defaults to `rprivate` for both bind mounts and
   485  volume mounts, and is only configurable for bind mounts. In other words, named
   486  volumes do not support bind propagation.
   487  
   488  - **`shared`**: Sub-mounts of the original mount are exposed to replica mounts,
   489                  and sub-mounts of replica mounts are also propagated to the
   490                  original mount.
   491  - **`slave`**: similar to a shared mount, but only in one direction. If the
   492                 original mount exposes a sub-mount, the replica mount can see it.
   493                 However, if the replica mount exposes a sub-mount, the original
   494                 mount cannot see it.
   495  - **`private`**: The mount is private. Sub-mounts within it are not exposed to
   496                   replica mounts, and sub-mounts of replica mounts are not
   497                   exposed to the original mount.
   498  - **`rshared`**: The same as shared, but the propagation also extends to and from
   499                   mount points nested within any of the original or replica mount
   500                   points.
   501  - **`rslave`**: The same as `slave`, but the propagation also extends to and from
   502                   mount points nested within any of the original or replica mount
   503                   points.
   504  - **`rprivate`**: The default. The same as `private`, meaning that no mount points
   505                    anywhere within the original or replica mount points propagate
   506                    in either direction.
   507  
   508  For more information about bind propagation, see the
   509  [Linux kernel documentation for shared subtree](https://www.kernel.org/doc/Documentation/filesystems/sharedsubtree.txt).
   510  
   511  #### Options for named volumes
   512  
   513  The following options can only be used for named volumes (`type=volume`):
   514  
   515  
   516  <table>
   517    <tr>
   518      <th>Option</th>
   519      <th>Description</th>
   520    </tr>
   521    <tr>
   522      <td><b>volume-driver</b></td>
   523      <td>
   524        <p>Name of the volume-driver plugin to use for the volume. Defaults to
   525        <tt>"local"</tt>, to use the local volume driver to create the volume if the
   526        volume does not exist.</p>
   527      </td>
   528    </tr>
   529    <tr>
   530      <td><b>volume-label</b></td>
   531      <td>
   532        One or more custom metadata ("labels") to apply to the volume upon
   533        creation. For example,
   534        <tt>volume-label=mylabel=hello-world,my-other-label=hello-mars</tt>. For more
   535        information about labels, refer to
   536        <a href="https://docs.docker.com/config/labels-custom-metadata/">apply custom metadata</a>.
   537      </td>
   538    </tr>
   539    <tr>
   540      <td><b>volume-nocopy</b></td>
   541      <td>
   542        By default, if you attach an empty volume to a container, and files or
   543        directories already existed at the mount-path in the container (<tt>dst</tt>),
   544        the Engine copies those files and directories into the volume, allowing
   545        the host to access them. Set <tt>volume-nocopy</tt> to disable copying files
   546        from the container's filesystem to the volume and mount the empty volume.<br />
   547        <br />
   548        A value is optional:<br />
   549        <br />
   550        <ul>
   551          <li><tt>true</tt> or <tt>1</tt>: Default if you do not provide a value. Disables copying.</li>
   552          <li><tt>false</tt> or <tt>0</tt>: Enables copying.</li>
   553        </ul>
   554      </td>
   555    </tr>
   556    <tr>
   557      <td><b>volume-opt</b></td>
   558      <td>
   559        Options specific to a given volume driver, which will be passed to the
   560        driver when creating the volume. Options are provided as a comma-separated
   561        list of key/value pairs, for example,
   562        <tt>volume-opt=some-option=some-value,volume-opt=some-other-option=some-other-value</tt>.
   563        For available options for a given driver, refer to that driver's
   564        documentation.
   565      </td>
   566    </tr>
   567  </table>
   568  
   569  
   570  #### Options for tmpfs
   571  
   572  The following options can only be used for tmpfs mounts (`type=tmpfs`);
   573  
   574  
   575  <table>
   576    <tr>
   577      <th>Option</th>
   578      <th>Description</th>
   579    </tr>
   580    <tr>
   581      <td><b>tmpfs-size</b></td>
   582      <td>Size of the tmpfs mount in bytes. Unlimited by default in Linux.</td>
   583    </tr>
   584    <tr>
   585      <td><b>tmpfs-mode</b></td>
   586      <td>File mode of the tmpfs in octal. (e.g. <tt>"700"</tt> or <tt>"0700"</tt>.) Defaults to <tt>"1777"</tt> in Linux.</td>
   587    </tr>
   588  </table>
   589  
   590  
   591  #### Differences between "--mount" and "--volume"
   592  
   593  The `--mount` flag supports most options that are supported by the `-v`
   594  or `--volume` flag for `docker run`, with some important exceptions:
   595  
   596  - The `--mount` flag allows you to specify a volume driver and volume driver
   597    options *per volume*, without creating the volumes in advance. In contrast,
   598    `docker run` allows you to specify a single volume driver which is shared
   599    by all volumes, using the `--volume-driver` flag.
   600  
   601  - The `--mount` flag allows you to specify custom metadata ("labels") for a volume,
   602    before the volume is created.
   603  
   604  - When you use `--mount` with `type=bind`, the host-path must refer to an *existing*
   605    path on the host. The path will not be created for you and the service will fail
   606    with an error if the path does not exist.
   607  
   608  - The `--mount` flag does not allow you to relabel a volume with `Z` or `z` flags,
   609    which are used for `selinux` labeling.
   610  
   611  #### Create a service using a named volume
   612  
   613  The following example creates a service that uses a named volume:
   614  
   615  ```console
   616  $ docker service create \
   617    --name my-service \
   618    --replicas 3 \
   619    --mount type=volume,source=my-volume,destination=/path/in/container,volume-label="color=red",volume-label="shape=round" \
   620    nginx:alpine
   621  ```
   622  
   623  For each replica of the service, the engine requests a volume named "my-volume"
   624  from the default ("local") volume driver where the task is deployed. If the
   625  volume does not exist, the engine creates a new volume and applies the "color"
   626  and "shape" labels.
   627  
   628  When the task is started, the volume is mounted on `/path/in/container/` inside
   629  the container.
   630  
   631  Be aware that the default ("local") volume is a locally scoped volume driver.
   632  This means that depending on where a task is deployed, either that task gets a
   633  *new* volume named "my-volume", or shares the same "my-volume" with other tasks
   634  of the same service. Multiple containers writing to a single shared volume can
   635  cause data corruption if the software running inside the container is not
   636  designed to handle concurrent processes writing to the same location. Also take
   637  into account that containers can be re-scheduled by the Swarm orchestrator and
   638  be deployed on a different node.
   639  
   640  #### Create a service that uses an anonymous volume
   641  
   642  The following command creates a service with three replicas with an anonymous
   643  volume on `/path/in/container`:
   644  
   645  ```console
   646  $ docker service create \
   647    --name my-service \
   648    --replicas 3 \
   649    --mount type=volume,destination=/path/in/container \
   650    nginx:alpine
   651  ```
   652  
   653  In this example, no name (`source`) is specified for the volume, so a new volume
   654  is created for each task. This guarantees that each task gets its own volume,
   655  and volumes are not shared between tasks. Anonymous volumes are removed after
   656  the task using them is complete.
   657  
   658  #### Create a service that uses a bind-mounted host directory
   659  
   660  The following example bind-mounts a host directory at `/path/in/container` in
   661  the containers backing the service:
   662  
   663  ```console
   664  $ docker service create \
   665    --name my-service \
   666    --mount type=bind,source=/path/on/host,destination=/path/in/container \
   667    nginx:alpine
   668  ```
   669  
   670  ### Set service mode (--mode)
   671  
   672  The service mode determines whether this is a _replicated_ service or a _global_
   673  service. A replicated service runs as many tasks as specified, while a global
   674  service runs on each active node in the swarm.
   675  
   676  The following command creates a global service:
   677  
   678  ```console
   679  $ docker service create \
   680   --name redis_2 \
   681   --mode global \
   682   redis:3.0.6
   683  ```
   684  
   685  ### <a name="constraint"></a> Specify service constraints (--constraint)
   686  
   687  You can limit the set of nodes where a task can be scheduled by defining
   688  constraint expressions. Constraint expressions can either use a _match_ (`==`)
   689  or _exclude_ (`!=`) rule. Multiple constraints find nodes that satisfy every
   690  expression (AND match). Constraints can match node or Docker Engine labels as
   691  follows:
   692  
   693  | node attribute       | matches                        | example                                       |
   694  |----------------------|--------------------------------|-----------------------------------------------|
   695  | `node.id`            | Node ID                        | `node.id==2ivku8v2gvtg4`                      |
   696  | `node.hostname`      | Node hostname                  | `node.hostname!=node-2`                       |
   697  | `node.role`          | Node role (`manager`/`worker`) | `node.role==manager`                          |
   698  | `node.platform.os`   | Node operating system          | `node.platform.os==windows`                   |
   699  | `node.platform.arch` | Node architecture              | `node.platform.arch==x86_64`                  |
   700  | `node.labels`        | User-defined node labels       | `node.labels.security==high`                  |
   701  | `engine.labels`      | Docker Engine's labels         | `engine.labels.operatingsystem==ubuntu-22.04` |
   702  
   703  `engine.labels` apply to Docker Engine labels like operating system, drivers,
   704  etc. Swarm administrators add `node.labels` for operational purposes by using
   705  the [`docker node update`](node_update.md) command.
   706  
   707  For example, the following limits tasks for the redis service to nodes where the
   708  node type label equals queue:
   709  
   710  ```console
   711  $ docker service create \
   712    --name redis_2 \
   713    --constraint node.platform.os==linux \
   714    --constraint node.labels.type==queue \
   715    redis:3.0.6
   716  ```
   717  
   718  If the service constraints exclude all nodes in the cluster, a message is printed
   719  that no suitable node is found, but the scheduler will start a reconciliation
   720  loop and deploy the service once a suitable node becomes available.
   721  
   722  In the example below, no node satisfying the constraint was found, causing the
   723  service to not reconcile with the desired state:
   724  
   725  ```console
   726  $ docker service create \
   727    --name web \
   728    --constraint node.labels.region==east \
   729    nginx:alpine
   730  
   731  lx1wrhhpmbbu0wuk0ybws30bc
   732  overall progress: 0 out of 1 tasks
   733  1/1: no suitable node (scheduling constraints not satisfied on 5 nodes)
   734  
   735  $ docker service ls
   736  ID                  NAME     MODE         REPLICAS   IMAGE               PORTS
   737  b6lww17hrr4e        web      replicated   0/1        nginx:alpine
   738  ```
   739  
   740  After adding the `region=east` label to a node in the cluster, the service
   741  reconciles, and the desired number of replicas are deployed:
   742  
   743  ```console
   744  $ docker node update --label-add region=east yswe2dm4c5fdgtsrli1e8ya5l
   745  yswe2dm4c5fdgtsrli1e8ya5l
   746  
   747  $ docker service ls
   748  ID                  NAME     MODE         REPLICAS   IMAGE               PORTS
   749  b6lww17hrr4e        web      replicated   1/1        nginx:alpine
   750  ```
   751  
   752  ### <a name="placement-pref"></a> Specify service placement preferences (--placement-pref)
   753  
   754  You can set up the service to divide tasks evenly over different categories of
   755  nodes. One example of where this can be useful is to balance tasks over a set
   756  of datacenters or availability zones. The example below illustrates this:
   757  
   758  ```console
   759  $ docker service create \
   760    --replicas 9 \
   761    --name redis_2 \
   762    --placement-pref spread=node.labels.datacenter \
   763    redis:3.0.6
   764  ```
   765  
   766  This uses `--placement-pref` with a `spread` strategy (currently the only
   767  supported strategy) to spread tasks evenly over the values of the `datacenter`
   768  node label. In this example, we assume that every node has a `datacenter` node
   769  label attached to it. If there are three different values of this label among
   770  nodes in the swarm, one third of the tasks will be placed on the nodes
   771  associated with each value. This is true even if there are more nodes with one
   772  value than another. For example, consider the following set of nodes:
   773  
   774  - Three nodes with `node.labels.datacenter=east`
   775  - Two nodes with `node.labels.datacenter=south`
   776  - One node with `node.labels.datacenter=west`
   777  
   778  Since we are spreading over the values of the `datacenter` label and the
   779  service has 9 replicas, 3 replicas will end up in each datacenter. There are
   780  three nodes associated with the value `east`, so each one will get one of the
   781  three replicas reserved for this value. There are two nodes with the value
   782  `south`, and the three replicas for this value will be divided between them,
   783  with one receiving two replicas and another receiving just one. Finally, `west`
   784  has a single node that will get all three replicas reserved for `west`.
   785  
   786  If the nodes in one category (for example, those with
   787  `node.labels.datacenter=south`) can't handle their fair share of tasks due to
   788  constraints or resource limitations, the extra tasks will be assigned to other
   789  nodes instead, if possible.
   790  
   791  Both engine labels and node labels are supported by placement preferences. The
   792  example above uses a node label, because the label is referenced with
   793  `node.labels.datacenter`. To spread over the values of an engine label, use
   794  `--placement-pref spread=engine.labels.<labelname>`.
   795  
   796  It is possible to add multiple placement preferences to a service. This
   797  establishes a hierarchy of preferences, so that tasks are first divided over
   798  one category, and then further divided over additional categories. One example
   799  of where this may be useful is dividing tasks fairly between datacenters, and
   800  then splitting the tasks within each datacenter over a choice of racks. To add
   801  multiple placement preferences, specify the `--placement-pref` flag multiple
   802  times. The order is significant, and the placement preferences will be applied
   803  in the order given when making scheduling decisions.
   804  
   805  The following example sets up a service with multiple placement preferences.
   806  Tasks are spread first over the various datacenters, and then over racks
   807  (as indicated by the respective labels):
   808  
   809  ```console
   810  $ docker service create \
   811    --replicas 9 \
   812    --name redis_2 \
   813    --placement-pref 'spread=node.labels.datacenter' \
   814    --placement-pref 'spread=node.labels.rack' \
   815    redis:3.0.6
   816  ```
   817  
   818  When updating a service with `docker service update`, `--placement-pref-add`
   819  appends a new placement preference after all existing placement preferences.
   820  `--placement-pref-rm` removes an existing placement preference that matches the
   821  argument.
   822  
   823  ### <a name="reserve-memory"></a> Specify memory requirements and constraints for a service (--reserve-memory and --limit-memory)
   824  
   825  If your service needs a minimum amount of memory in order to run correctly,
   826  you can use `--reserve-memory` to specify that the service should only be
   827  scheduled on a node with this much memory available to reserve. If no node is
   828  available that meets the criteria, the task is not scheduled, but remains in a
   829  pending state.
   830  
   831  The following example requires that 4GB of memory be available and reservable
   832  on a given node before scheduling the service to run on that node.
   833  
   834  ```console
   835  $ docker service create --reserve-memory=4GB --name=too-big nginx:alpine
   836  ```
   837  
   838  The managers won't schedule a set of containers on a single node whose combined
   839  reservations exceed the memory available on that node.
   840  
   841  After a task is scheduled and running, `--reserve-memory` does not enforce a
   842  memory limit. Use `--limit-memory` to ensure that a task uses no more than a
   843  given amount of memory on a node. This example limits the amount of memory used
   844  by the task to 4GB. The task will be scheduled even if each of your nodes has
   845  only 2GB of memory, because `--limit-memory` is an upper limit.
   846  
   847  ```console
   848  $ docker service create --limit-memory=4GB --name=too-big nginx:alpine
   849  ```
   850  
   851  Using `--reserve-memory` and `--limit-memory` does not guarantee that Docker
   852  will not use more memory on your host than you want. For instance, you could
   853  create many services, the sum of whose memory usage could exhaust the available
   854  memory.
   855  
   856  You can prevent this scenario from exhausting the available memory by taking
   857  into account other (non-containerized) software running on the host as well. If
   858  `--reserve-memory` is greater than or equal to `--limit-memory`, Docker won't
   859  schedule a service on a host that doesn't have enough memory. `--limit-memory`
   860  will limit the service's memory to stay within that limit, so if every service
   861  has a memory-reservation and limit set, Docker services will be less likely to
   862  saturate the host. Other non-service containers or applications running directly
   863  on the Docker host could still exhaust memory.
   864  
   865  There is a downside to this approach. Reserving memory also means that you may
   866  not make optimum use of the memory available on the node. Consider a service
   867  that under normal circumstances uses 100MB of memory, but depending on load can
   868  "peak" at 500MB. Reserving 500MB for that service (to guarantee can have 500MB
   869  for those "peaks") results in 400MB of memory being wasted most of the time.
   870  
   871  In short, you can take a more conservative or more flexible approach:
   872  
   873  - **Conservative**: reserve 500MB, and limit to 500MB. Basically you're now
   874    treating the service containers as VMs, and you may be losing a big advantage
   875    containers, which is greater density of services per host.
   876  
   877  - **Flexible**: limit to 500MB in the assumption that if the service requires
   878    more than 500MB, it is malfunctioning. Reserve something between the 100MB
   879    "normal" requirement and the 500MB "peak" requirement". This assumes that when
   880    this service is at "peak", other services or non-container workloads probably
   881    won't be.
   882  
   883  The approach you take depends heavily on the memory-usage patterns of your
   884  workloads. You should test under normal and peak conditions before settling
   885  on an approach.
   886  
   887  On Linux, you can also limit a service's overall memory footprint on a given
   888  host at the level of the host operating system, using `cgroups` or other
   889  relevant operating system tools.
   890  
   891  ### <a name="replicas-max-per-node"></a> Specify maximum replicas per node (--replicas-max-per-node)
   892  
   893  Use the `--replicas-max-per-node` flag to set the maximum number of replica tasks that can run on a node.
   894  The following command creates a nginx service with 2 replica tasks but only one replica task per node.
   895  
   896  One example where this can be useful is to balance tasks over a set of data centers together with `--placement-pref`
   897  and let `--replicas-max-per-node` setting make sure that replicas are not migrated to another datacenter during
   898  maintenance or datacenter failure.
   899  
   900  The example below illustrates this:
   901  
   902  ```console
   903  $ docker service create \
   904    --name nginx \
   905    --replicas 2 \
   906    --replicas-max-per-node 1 \
   907    --placement-pref 'spread=node.labels.datacenter' \
   908    nginx
   909  ```
   910  
   911  ### <a name="network"></a> Attach a service to an existing network (--network)
   912  
   913  You can use overlay networks to connect one or more services within the swarm.
   914  
   915  First, create an overlay network on a manager node the docker network create
   916  command:
   917  
   918  ```console
   919  $ docker network create --driver overlay my-network
   920  
   921  etjpu59cykrptrgw0z0hk5snf
   922  ```
   923  
   924  After you create an overlay network in swarm mode, all manager nodes have
   925  access to the network.
   926  
   927  When you create a service and pass the `--network` flag to attach the service to
   928  the overlay network:
   929  
   930  ```console
   931  $ docker service create \
   932    --replicas 3 \
   933    --network my-network \
   934    --name my-web \
   935    nginx
   936  
   937  716thylsndqma81j6kkkb5aus
   938  ```
   939  
   940  The swarm extends my-network to each node running the service.
   941  
   942  Containers on the same network can access each other using
   943  [service discovery](https://docs.docker.com/network/drivers/overlay/#container-discovery).
   944  
   945  Long form syntax of `--network` allows to specify list of aliases and driver options:
   946  `--network name=my-network,alias=web1,driver-opt=field1=value1`
   947  
   948  ### <a name="publish"></a> Publish service ports externally to the swarm (-p, --publish)
   949  
   950  You can publish service ports to make them available externally to the swarm
   951  using the `--publish` flag. The `--publish` flag can take two different styles
   952  of arguments. The short version is positional, and allows you to specify the
   953  published port and target port separated by a colon (`:`).
   954  
   955  ```console
   956  $ docker service create --name my_web --replicas 3 --publish 8080:80 nginx
   957  ```
   958  
   959  There is also a long format, which is easier to read and allows you to specify
   960  more options. The long format is preferred. You cannot specify the service's
   961  mode when using the short format. Here is an example of using the long format
   962  for the same service as above:
   963  
   964  ```console
   965  $ docker service create --name my_web --replicas 3 --publish published=8080,target=80 nginx
   966  ```
   967  
   968  The options you can specify are:
   969  
   970  <table>
   971  <thead>
   972  <tr>
   973    <th>Option</th>
   974    <th>Short syntax</th>
   975    <th>Long syntax</th>
   976    <th>Description</th>
   977  </tr>
   978  </thead>
   979  <tr>
   980    <td>published and target port</td>
   981    <td><tt>--publish 8080:80</tt></td>
   982    <td><tt>--publish published=8080,target=80</tt></td>
   983    <td><p>
   984      The target port within the container and the port to map it to on the
   985      nodes, using the routing mesh (<tt>ingress</tt>) or host-level networking.
   986      More options are available, later in this table. The key-value syntax is
   987      preferred, because it is somewhat self-documenting.
   988    </p></td>
   989  </tr>
   990  <tr>
   991    <td>mode</td>
   992    <td>Not possible to set using short syntax.</td>
   993    <td><tt>--publish published=8080,target=80,mode=host</tt></td>
   994    <td><p>
   995      The mode to use for binding the port, either <tt>ingress</tt> or <tt>host</tt>.
   996      Defaults to <tt>ingress</tt> to use the routing mesh.
   997    </p></td>
   998  </tr>
   999  <tr>
  1000    <td>protocol</td>
  1001    <td><tt>--publish 8080:80/tcp</tt></td>
  1002    <td><tt>--publish published=8080,target=80,protocol=tcp</tt></td>
  1003    <td><p>
  1004      The protocol to use, <tt>tcp</tt> , <tt>udp</tt>, or <tt>sctp</tt>. Defaults to
  1005      <tt>tcp</tt>. To bind a port for both protocols, specify the <tt>-p</tt> or
  1006      <tt>--publish</tt> flag twice.
  1007    </p></td>
  1008  </tr>
  1009  </table>
  1010  
  1011  When you publish a service port using `ingress` mode, the swarm routing mesh
  1012  makes the service accessible at the published port on every node regardless if
  1013  there is a task for the service running on the node. If you use `host` mode,
  1014  the port is only bound on nodes where the service is running, and a given port
  1015  on a node can only be bound once. You can only set the publication mode using
  1016  the long syntax. For more information refer to
  1017  [Use swarm mode routing mesh](https://docs.docker.com/engine/swarm/ingress/).
  1018  
  1019  ### <a name="credentials-spec"></a> Provide credential specs for managed service accounts (--credentials-spec)
  1020  
  1021  This option is only used for services using Windows containers. The
  1022  `--credential-spec` must be in the format `file://<filename>` or
  1023  `registry://<value-name>`.
  1024  
  1025  When using the `file://<filename>` format, the referenced file must be
  1026  present in the `CredentialSpecs` subdirectory in the docker data directory,
  1027  which defaults to `C:\ProgramData\Docker\` on Windows. For example,
  1028  specifying `file://spec.json` loads `C:\ProgramData\Docker\CredentialSpecs\spec.json`.
  1029  
  1030  When using the `registry://<value-name>` format, the credential spec is
  1031  read from the Windows registry on the daemon's host. The specified
  1032  registry value must be located in:
  1033  
  1034      HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Virtualization\Containers\CredentialSpecs
  1035  
  1036  
  1037  ### Create services using templates
  1038  
  1039  You can use templates for some flags of `service create`, using the syntax
  1040  provided by the Go's [text/template](https://pkg.go.dev/text/template) package.
  1041  
  1042  The supported flags are the following :
  1043  
  1044  - `--hostname`
  1045  - `--mount`
  1046  - `--env`
  1047  
  1048  Valid placeholders for the Go template are listed below:
  1049  
  1050  
  1051  <table>
  1052    <tr>
  1053      <th>Placeholder</th>
  1054      <th>Description</th>
  1055    </tr>
  1056    <tr>
  1057      <td><tt>.Service.ID</tt></td>
  1058      <td>Service ID</td>
  1059    </tr>
  1060    <tr>
  1061      <td><tt>.Service.Name</tt></td>
  1062      <td>Service name</td>
  1063    </tr>
  1064    <tr>
  1065      <td><tt>.Service.Labels</tt></td>
  1066      <td>Service labels</td>
  1067    </tr>
  1068    <tr>
  1069      <td><tt>.Node.ID</tt></td>
  1070      <td>Node ID</td>
  1071    </tr>
  1072    <tr>
  1073      <td><tt>.Node.Hostname</tt></td>
  1074      <td>Node Hostname</td>
  1075    </tr>
  1076    <tr>
  1077      <td><tt>.Task.ID</tt></td>
  1078      <td>Task ID</td>
  1079    </tr>
  1080    <tr>
  1081      <td><tt>.Task.Name</tt></td>
  1082      <td>Task name</td>
  1083    </tr>
  1084    <tr>
  1085      <td><tt>.Task.Slot</tt></td>
  1086      <td>Task slot</td>
  1087    </tr>
  1088  </table>
  1089  
  1090  
  1091  #### Template example
  1092  
  1093  In this example, we are going to set the template of the created containers based on the
  1094  service's name, the node's ID and hostname where it sits.
  1095  
  1096  ```console
  1097  $ docker service create \
  1098      --name hosttempl \
  1099      --hostname="{{.Node.Hostname}}-{{.Node.ID}}-{{.Service.Name}}"\
  1100      busybox top
  1101  
  1102  va8ew30grofhjoychbr6iot8c
  1103  
  1104  $ docker service ps va8ew30grofhjoychbr6iot8c
  1105  
  1106  ID            NAME         IMAGE                                                                                   NODE          DESIRED STATE  CURRENT STATE               ERROR  PORTS
  1107  wo41w8hg8qan  hosttempl.1  busybox:latest@sha256:29f5d56d12684887bdfa50dcd29fc31eea4aaf4ad3bec43daf19026a7ce69912  2e7a8a9c4da2  Running        Running about a minute ago
  1108  
  1109  $ docker inspect --format="{{.Config.Hostname}}" 2e7a8a9c4da2-wo41w8hg8qanxwjwsg4kxpprj-hosttempl
  1110  
  1111  x3ti0erg11rjpg64m75kej2mz-hosttempl
  1112  ```
  1113  
  1114  ### <a name="isolation"></a> Specify isolation mode on Windows (--isolation)
  1115  
  1116  By default, tasks scheduled on Windows nodes are run using the default isolation mode
  1117  configured for this particular node. To force a specific isolation mode, you can use
  1118  the `--isolation` flag:
  1119  
  1120  ```console
  1121  $ docker service create --name myservice --isolation=process microsoft/nanoserver
  1122  ```
  1123  
  1124  Supported isolation modes on Windows are:
  1125  - `default`: use default settings specified on the node running the task
  1126  - `process`: use process isolation (Windows server only)
  1127  - `hyperv`: use Hyper-V isolation
  1128  
  1129  ### <a name="generic-resources"></a> Create services requesting Generic Resources (--generic-resources)
  1130  
  1131  You can narrow the kind of nodes your task can land on through the using the
  1132  `--generic-resource` flag (if the nodes advertise these resources):
  1133  
  1134  ```console
  1135  $ docker service create \
  1136      --name cuda \
  1137      --generic-resource "NVIDIA-GPU=2" \
  1138      --generic-resource "SSD=1" \
  1139      nvidia/cuda
  1140  ```
  1141  
  1142  ### Running as a job
  1143  
  1144  Jobs are a special kind of service designed to run an operation to completion
  1145  and then stop, as opposed to running long-running daemons. When a Task
  1146  belonging to a job exits successfully (return value 0), the Task is marked as
  1147  "Completed", and is not run again.
  1148  
  1149  Jobs are started by using one of two modes, `replicated-job` or `global-job`
  1150  
  1151  ```console
  1152  $ docker service create --name myjob \
  1153                          --mode replicated-job \
  1154                          bash "true"
  1155  ```
  1156  
  1157  This command will run one Task, which will, using the `bash` image, execute the
  1158  command `true`, which will return 0 and then exit.
  1159  
  1160  Though Jobs are ultimately a different kind of service, they a couple of
  1161  caveats compared to other services:
  1162  
  1163  - None of the update or rollback configuration options are valid.  Jobs can be
  1164    updated, but cannot be rolled out or rolled back, making these configuration
  1165    options moot.
  1166  - Jobs are never restarted on reaching the `Complete` state. This means that
  1167    for jobs, setting `--restart-condition` to `any` is the same as setting it to
  1168    `on-failure`.
  1169  
  1170  Jobs are available in both replicated and global modes.
  1171  
  1172  #### Replicated Jobs
  1173  
  1174  A replicated job is like a replicated service. Setting the `--replicas` flag
  1175  will specify total number of iterations of a job to execute.
  1176  
  1177  By default, all replicas of a replicated job will launch at once. To control
  1178  the total number of replicas that are executing simultaneously at any one time,
  1179  the `--max-concurrent` flag can be used:
  1180  
  1181  ```console
  1182  $ docker service create \
  1183      --name mythrottledjob \
  1184      --mode replicated-job \
  1185      --replicas 10 \
  1186      --max-concurrent 2 \
  1187      bash "true"
  1188  ```
  1189  
  1190  The above command will execute 10 Tasks in total, but only 2 of them will be
  1191  run at any given time.
  1192  
  1193  #### Global Jobs
  1194  
  1195  Global jobs are like global services, in that a Task is executed once on each node
  1196  matching placement constraints. Global jobs are represented by the mode `global-job`.
  1197  
  1198  Note that after a Global job is created, any new Nodes added to the cluster
  1199  will have a Task from that job started on them. The Global Job does not as a
  1200  whole have a "done" state, except insofar as every Node meeting the job's
  1201  constraints has a Completed task.
  1202  
  1203  ## Related commands
  1204  
  1205  * [service inspect](service_inspect.md)
  1206  * [service logs](service_logs.md)
  1207  * [service ls](service_ls.md)
  1208  * [service ps](service_ps.md)
  1209  * [service rm](service_rm.md)
  1210  * [service rollback](service_rollback.md)
  1211  * [service scale](service_scale.md)
  1212  * [service update](service_update.md)
  1213  
  1214  <style>table tr > td:first-child { white-space: nowrap;}</style>