This example refers to the two nodes in our swarm as `host1` and `host2`. This
example also uses Linux hosts, but the same commands work on Windows.
### Walk-through
1. Set up the swarm.
a. On `host1`, initialize a swarm (and if prompted, use `--advertise-addr`
to specify the IP address for the interface that communicates with other
hosts in the swarm, for instance, the private IP address on AWS):
```console
$ docker swarm init
Swarm initialized: current node (vz1mm9am11qcmo979tlrlox42) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-5g90q48weqrtqryq4kj6ow0e8xm9wmv9o6vgqc5j320ymybd5c-8ex8j0bc40s6hgvy5ui5gl4gy 172.31.47.252:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
```
b. On `host2`, join the swarm as instructed above:
```console
$ docker swarm join --token <your_token> <your_ip_address>:2377
This node joined a swarm as a worker.
```
If the node fails to join the swarm, the `docker swarm join` command times
out. To resolve, run `docker swarm leave --force` on `host2`, verify your
network and firewall settings, and try again.
2. On `host1`, create an attachable overlay network called `test-net`:
```console
$ docker network create --driver=overlay --attachable test-net
uqsof8phj3ak0rq9k86zta6ht
```
> Notice the returned **NETWORK ID** -- you will see it again when you connect to it from `host2`.
3. On `host1`, start an interactive (`-it`) container (`alpine1`) that connects to `test-net`:
```console
$ docker run -it --name alpine1 --network test-net alpine
/ #
```
4. On `host2`, list the available networks -- notice that `test-net` does not yet exist:
```console
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
ec299350b504 bridge bridge local
66e77d0d0e9a docker_gwbridge bridge local
9f6ae26ccb82 host host local
omvdxqrda80z ingress overlay swarm
b65c952a4b2b none null local
```
5. On `host2`, start a detached (`-d`) and interactive (`-it`) container (`alpine2`) that connects to `test-net`:
```console
$ docker run -dit --name alpine2 --network test-net alpine