$ docker service create \
--mode global \
--publish mode=host,target=80,published=8080 \
--name=nginx \
nginx:latest
```
You can reach the nginx server on port 8080 of every swarm node. If you add a
node to the swarm, a nginx task is started on it. You cannot start another
service or container on any swarm node which binds to port 8080.
> [!NOTE]
>
> This is a purely illustrative example. Creating an application-layer
> routing framework for a multi-tiered service is complex and out of scope for
> this topic.
### Connect the service to an overlay network
You can use overlay networks to connect one or more services within the swarm.
First, create overlay network on a manager node using the `docker network create`
command with the `--driver overlay` flag.
```console
$ docker network create --driver overlay my-network
```
After you create an overlay network in swarm mode, all manager nodes have access
to the network.
You can create a new service and pass the `--network` flag to attach the service
to the overlay network:
```console
$ docker service create \
--replicas 3 \
--network my-network \
--name my-web \
nginx
```
The swarm extends `my-network` to each node running the service.
You can also connect an existing service to an overlay network using the
`--network-add` flag.
```console
$ docker service update --network-add my-network my-web
```
To disconnect a running service from a network, use the `--network-rm` flag.
```console
$ docker service update --network-rm my-network my-web
```
For more information on overlay networking and service discovery, refer to
[Attach services to an overlay network](networking.md) and
[Docker swarm mode overlay network security model](/manuals/engine/network/drivers/overlay.md).
### Grant a service access to secrets
To create a service with access to Docker-managed secrets, use the `--secret`
flag. For more information, see
[Manage sensitive strings (secrets) for Docker services](secrets.md)
### Customize a service's isolation mode
> [!IMPORTANT]
>
> This setting applies to Windows hosts only and is ignored for Linux hosts.
Docker allows you to specify a swarm service's isolation
mode. The isolation mode can be one of the following:
- `default`: Use the default isolation mode configured for the Docker host, as
configured by the `-exec-opt` flag or `exec-opts` array in `daemon.json`. If
the daemon does not specify an isolation technology, `process` is the default
for Windows Server, and `hyperv` is the default (and only) choice for
Windows 10.
- `process`: Run the service tasks as a separate process on the host.
> [!NOTE]
>
> `process` isolation mode is only supported on Windows Server.
> Windows 10 only supports `hyperv` isolation mode.
- `hyperv`: Run the service tasks as isolated `hyperv` tasks. This increases
overhead but provides more isolation.
You can specify the isolation mode when creating or updating a new service using
the `--isolation` flag.
### Control service placement
Swarm services provide a few different ways for you to control scale and
placement of services on different nodes.
- You can specify whether the service needs to run a specific number of replicas
or should run globally on every worker node. See
[Replicated or global services](#replicated-or-global-services).
- You can configure the service's
[CPU or memory requirements](#reserve-memory-or-cpus-for-a-service), and the
service only runs on nodes which can meet those requirements.
- [Placement constraints](#placement-constraints) let you configure the service
to run only on nodes with specific (arbitrary) metadata set, and cause the
deployment to fail if appropriate nodes do not exist. For instance, you can
specify that your service should only run on nodes where an arbitrary label
`pci_compliant` is set to `true`.
- [Placement preferences](#placement-preferences) let you apply an arbitrary
label with a range of values to each node, and spread your service's tasks