Updates primarily to expand usage of Swarm cluster and make Compose
section more verbose plus other minor corrections.
Signed-off-by: David Currie <david_currie@uk.ibm.com>
| ... | ... |
@@ -7,13 +7,13 @@ keywords = ["Examples, Usage, network, docker, documentation, user guide, multih |
| 7 | 7 |
parent = "smn_networking" |
| 8 | 8 |
weight=-3 |
| 9 | 9 |
+++ |
| 10 |
-<![end-metadata]--> |
|
| 10 |
+<![end-metadata]--> |
|
| 11 | 11 |
|
| 12 | 12 |
# Get started with multi-host networking |
| 13 | 13 |
|
| 14 | 14 |
This article uses an example to explain the basics of creating a multi-host |
| 15 |
-network. Docker Engine supports multi-host-networking out-of-the-box through the |
|
| 16 |
-`overlay` network driver. Unlike `bridge` networks overlay networks require |
|
| 15 |
+network. Docker Engine supports multi-host networking out-of-the-box through the |
|
| 16 |
+`overlay` network driver. Unlike `bridge` networks, overlay networks require |
|
| 17 | 17 |
some pre-existing conditions before you can create one. These conditions are: |
| 18 | 18 |
|
| 19 | 19 |
* A host with a 3.16 kernel version or higher. |
| ... | ... |
@@ -22,8 +22,8 @@ some pre-existing conditions before you can create one. These conditions are: |
| 22 | 22 |
* A properly configured Engine `daemon` on each host in the cluster. |
| 23 | 23 |
|
| 24 | 24 |
Though Docker Machine and Docker Swarm are not mandatory to experience Docker |
| 25 |
-multi-host-networking, this example uses them to illustrate how they are |
|
| 26 |
-integrated. You'll use Machine to create both the the key-value store |
|
| 25 |
+multi-host networking, this example uses them to illustrate how they are |
|
| 26 |
+integrated. You'll use Machine to create both the key-value store |
|
| 27 | 27 |
server and the host cluster. This example creates a Swarm cluster. |
| 28 | 28 |
|
| 29 | 29 |
## Prerequisites |
| ... | ... |
@@ -39,10 +39,10 @@ Machine to the latest versions. |
| 39 | 39 |
|
| 40 | 40 |
## Step 1: Set up a key-value store |
| 41 | 41 |
|
| 42 |
-An overlay network requires a key-value store. The key-value stores information |
|
| 43 |
-about the network state which includes discovery, networks, endpoints, |
|
| 44 |
-ip-addresses, and more. Docker supports Consul, Etcd, and ZooKeeper (Distributed |
|
| 45 |
-store) key-value stores. This example uses Consul. |
|
| 42 |
+An overlay network requires a key-value store. The key-value store holds |
|
| 43 |
+information about the network state which includes discovery, networks, |
|
| 44 |
+endpoints, IP addresses, and more. Docker supports Consul, Etcd, and ZooKeeper |
|
| 45 |
+key-value stores. This example uses Consul. |
|
| 46 | 46 |
|
| 47 | 47 |
1. Log into a system prepared with the prerequisite Docker Engine, Docker Machine, and VirtualBox software. |
| 48 | 48 |
|
| ... | ... |
@@ -62,9 +62,10 @@ store) key-value stores. This example uses Consul. |
| 62 | 62 |
-h "consul" \ |
| 63 | 63 |
progrium/consul -server -bootstrap |
| 64 | 64 |
|
| 65 |
- You passed the `docker run` command the connection configuration using a bash |
|
| 66 |
- expansion `$(docker-machine config mh-keystore)`. The client started a |
|
| 67 |
- `progrium/consul` image running in the `mh-keystore` machine. The server is called `consul`and is listening port `8500`. |
|
| 65 |
+ A bash expansion `$(docker-machine config mh-keystore)` is used to pass the |
|
| 66 |
+ connection configuration to the `docker run` command. The client starts a |
|
| 67 |
+ `progrium/consul` image running in the `mh-keystore` machine. The server is |
|
| 68 |
+ called `consul` and is listening on port `8500`. |
|
| 68 | 69 |
|
| 69 | 70 |
4. Set your local environment to the `mh-keystore` machine. |
| 70 | 71 |
|
| ... | ... |
@@ -82,7 +83,7 @@ Keep your terminal open and move onto the next step. |
| 82 | 82 |
## Step 2: Create a Swarm cluster |
| 83 | 83 |
|
| 84 | 84 |
In this step, you use `docker-machine` to provision the hosts for your network. |
| 85 |
-At this point, you won't actually created the network. You'll create several |
|
| 85 |
+At this point, you won't actually create the network. You'll create several |
|
| 86 | 86 |
machines in VirtualBox. One of the machines will act as the Swarm master; |
| 87 | 87 |
you'll create that first. As you create each host, you'll pass the Engine on |
| 88 | 88 |
that machine options that are needed by the `overlay` network driver. |
| ... | ... |
@@ -91,7 +92,7 @@ that machine options that are needed by the `overlay` network driver. |
| 91 | 91 |
|
| 92 | 92 |
$ docker-machine create \ |
| 93 | 93 |
-d virtualbox \ |
| 94 |
- --swarm --swarm-image="swarm" --swarm-master \ |
|
| 94 |
+ --swarm --swarm-master \ |
|
| 95 | 95 |
--swarm-discovery="consul://$(docker-machine ip mh-keystore):8500" \ |
| 96 | 96 |
--engine-opt="cluster-store=consul://$(docker-machine ip mh-keystore):8500" \ |
| 97 | 97 |
--engine-opt="cluster-advertise=eth1:2376" \ |
| ... | ... |
@@ -102,7 +103,7 @@ that machine options that are needed by the `overlay` network driver. |
| 102 | 102 |
2. Create another host and add it to the Swarm cluster. |
| 103 | 103 |
|
| 104 | 104 |
$ docker-machine create -d virtualbox \ |
| 105 |
- --swarm --swarm-image="swarm" \ |
|
| 105 |
+ --swarm \ |
|
| 106 | 106 |
--swarm-discovery="consul://$(docker-machine ip mh-keystore):8500" \ |
| 107 | 107 |
--engine-opt="cluster-store=consul://$(docker-machine ip mh-keystore):8500" \ |
| 108 | 108 |
--engine-opt="cluster-advertise=eth1:2376" \ |
| ... | ... |
@@ -112,14 +113,13 @@ that machine options that are needed by the `overlay` network driver. |
| 112 | 112 |
|
| 113 | 113 |
$ docker-machine ls |
| 114 | 114 |
NAME ACTIVE DRIVER STATE URL SWARM |
| 115 |
- default virtualbox Running tcp://192.168.99.100:2376 |
|
| 116 |
- mh-keystore virtualbox Running tcp://192.168.99.103:2376 |
|
| 117 |
- mhs-demo0 virtualbox Running tcp://192.168.99.104:2376 mhs-demo0 (master) |
|
| 118 |
- mhs-demo1 virtualbox Running tcp://192.168.99.105:2376 mhs-demo0 |
|
| 115 |
+ default - virtualbox Running tcp://192.168.99.100:2376 |
|
| 116 |
+ mh-keystore * virtualbox Running tcp://192.168.99.103:2376 |
|
| 117 |
+ mhs-demo0 - virtualbox Running tcp://192.168.99.104:2376 mhs-demo0 (master) |
|
| 118 |
+ mhs-demo1 - virtualbox Running tcp://192.168.99.105:2376 mhs-demo0 |
|
| 119 | 119 |
|
| 120 | 120 |
At this point you have a set of hosts running on your network. You are ready to create a multi-host network for containers using these hosts. |
| 121 | 121 |
|
| 122 |
- |
|
| 123 | 122 |
Leave your terminal open and go onto the next step. |
| 124 | 123 |
|
| 125 | 124 |
## Step 3: Create the overlay Network |
| ... | ... |
@@ -155,7 +155,7 @@ To create an overlay network |
| 155 | 155 |
Total Memory: 2.043 GiB |
| 156 | 156 |
Name: 30438ece0915 |
| 157 | 157 |
|
| 158 |
- From this information, you can see that you are running three containers and 2 images on the Master. |
|
| 158 |
+ From this information, you can see that you are running three containers and two images on the Master. |
|
| 159 | 159 |
|
| 160 | 160 |
3. Create your `overlay` network. |
| 161 | 161 |
|
| ... | ... |
@@ -167,54 +167,51 @@ To create an overlay network |
| 167 | 167 |
|
| 168 | 168 |
$ docker network ls |
| 169 | 169 |
NETWORK ID NAME DRIVER |
| 170 |
- 412c2496d0eb mhs-demo1/host host |
|
| 171 |
- dd51763e6dd2 mhs-demo0/bridge bridge |
|
| 172 |
- 6b07d0be843f my-net overlay |
|
| 173 |
- b4234109bd9b mhs-demo0/none null |
|
| 174 |
- 1aeead6dd890 mhs-demo0/host host |
|
| 175 |
- d0bb78cbe7bd mhs-demo1/bridge bridge |
|
| 176 |
- 1c0eb8f69ebb mhs-demo1/none null |
|
| 170 |
+ 412c2496d0eb mhs-demo1/host host |
|
| 171 |
+ dd51763e6dd2 mhs-demo0/bridge bridge |
|
| 172 |
+ 6b07d0be843f my-net overlay |
|
| 173 |
+ b4234109bd9b mhs-demo0/none null |
|
| 174 |
+ 1aeead6dd890 mhs-demo0/host host |
|
| 175 |
+ d0bb78cbe7bd mhs-demo1/bridge bridge |
|
| 176 |
+ 1c0eb8f69ebb mhs-demo1/none null |
|
| 177 | 177 |
|
| 178 |
- Because you are in the Swarm master environment, you see all the networks on all Swarm agents. Notice that each `NETWORK ID` is unique. The default networks on each engine and the single overlay network. |
|
| 178 |
+ As you are in the Swarm master environment, you see all the networks on all |
|
| 179 |
+ the Swarm agents: the default networks on each engine and the single overlay |
|
| 180 |
+ network. Notice that each `NETWORK ID` is unique. |
|
| 179 | 181 |
|
| 180 |
-5. Switch to each Swarm agent in turn and list the network. |
|
| 182 |
+5. Switch to each Swarm agent in turn and list the networks. |
|
| 181 | 183 |
|
| 182 | 184 |
$ eval $(docker-machine env mhs-demo0) |
| 183 | 185 |
$ docker network ls |
| 184 | 186 |
NETWORK ID NAME DRIVER |
| 185 |
- 6b07d0be843f my-net overlay |
|
| 186 |
- dd51763e6dd2 bridge bridge |
|
| 187 |
- b4234109bd9b none null |
|
| 188 |
- 1aeead6dd890 host host |
|
| 187 |
+ 6b07d0be843f my-net overlay |
|
| 188 |
+ dd51763e6dd2 bridge bridge |
|
| 189 |
+ b4234109bd9b none null |
|
| 190 |
+ 1aeead6dd890 host host |
|
| 189 | 191 |
$ eval $(docker-machine env mhs-demo1) |
| 190 | 192 |
$ docker network ls |
| 191 | 193 |
NETWORK ID NAME DRIVER |
| 192 |
- d0bb78cbe7bd bridge bridge |
|
| 193 |
- 1c0eb8f69ebb none null |
|
| 194 |
- 412c2496d0eb host host |
|
| 195 |
- 6b07d0be843f my-net overlay |
|
| 194 |
+ d0bb78cbe7bd bridge bridge |
|
| 195 |
+ 1c0eb8f69ebb none null |
|
| 196 |
+ 412c2496d0eb host host |
|
| 197 |
+ 6b07d0be843f my-net overlay |
|
| 196 | 198 |
|
| 197 |
- Both agents reports it has the `my-net `network with the `6b07d0be843f` id. You have a multi-host container network running! |
|
| 199 |
+ Both agents report they have the `my-net` network with the `6b07d0be843f` ID. |
|
| 200 |
+ You now have a multi-host container network running! |
|
| 198 | 201 |
|
| 199 | 202 |
## Step 4: Run an application on your Network |
| 200 | 203 |
|
| 201 | 204 |
Once your network is created, you can start a container on any of the hosts and it automatically is part of the network. |
| 202 | 205 |
|
| 203 |
-1. Point your environment to your `mhs-demo0` instance. |
|
| 206 |
+1. Point your environment to the Swarm master. |
|
| 204 | 207 |
|
| 205 |
- $ eval $(docker-machine env mhs-demo0) |
|
| 208 |
+ $ eval $(docker-machine env --swarm mhs-demo0) |
|
| 206 | 209 |
|
| 207 |
-2. Start an Nginx server on `mhs-demo0`. |
|
| 210 |
+2. Start an Nginx web server on the `mhs-demo0` instance. |
|
| 208 | 211 |
|
| 209 | 212 |
$ docker run -itd --name=web --net=my-net --env="constraint:node==mhs-demo0" nginx |
| 210 | 213 |
|
| 211 |
- This command starts a web server on the Swarm master. |
|
| 212 |
- |
|
| 213 |
-3. Point your Machine environment to `mhs-demo1` |
|
| 214 |
- |
|
| 215 |
- $ eval $(docker-machine env mhs-demo1) |
|
| 216 |
- |
|
| 217 |
-4. Run a Busybox instance and get the contents of the Ngnix server's home page. |
|
| 214 |
+4. Run a BusyBox instance on the `mhs-demo1` instance and get the contents of the Nginx server's home page. |
|
| 218 | 215 |
|
| 219 | 216 |
$ docker run -it --rm --net=my-net --env="constraint:node==mhs-demo1" busybox wget -O- http://web |
| 220 | 217 |
Unable to find image 'busybox:latest' locally |
| ... | ... |
@@ -284,7 +281,7 @@ to have external connectivity outside of their cluster. |
| 284 | 284 |
412c2496d0eb host host |
| 285 | 285 |
97102a22e8d2 docker_gwbridge bridge |
| 286 | 286 |
|
| 287 |
-2. Check the Ngnix container's network interfaces. |
|
| 287 |
+2. Check the Nginx container's network interfaces. |
|
| 288 | 288 |
|
| 289 | 289 |
$ docker exec web ip addr |
| 290 | 290 |
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default |
| ... | ... |
@@ -314,9 +311,11 @@ to have external connectivity outside of their cluster. |
| 314 | 314 |
|
| 315 | 315 |
You can try starting a second network on your existing Swarm cluster using Docker Compose. |
| 316 | 316 |
|
| 317 |
-1. Log into the Swarm master. |
|
| 317 |
+1. If you haven't already, install Docker Compose. |
|
| 318 | 318 |
|
| 319 |
-2. Install Docker Compose. |
|
| 319 |
+2. Change your environment to the Swarm master. |
|
| 320 |
+ |
|
| 321 |
+ $ eval $(docker-machine env --swarm mhs-demo0) |
|
| 320 | 322 |
|
| 321 | 323 |
3. Create a `docker-compose.yml` file. |
| 322 | 324 |
|
| ... | ... |
@@ -336,7 +335,15 @@ You can try starting a second network on your existing Swarm cluster using Docke |
| 336 | 336 |
|
| 337 | 337 |
6. Start the application with Compose. |
| 338 | 338 |
|
| 339 |
- $ docker-compose --x-networking up -d |
|
| 339 |
+ $ docker-compose --x-networking --project-name=counter up -d |
|
| 340 |
+ |
|
| 341 |
+7. Get the Swarm master's IP address. |
|
| 342 |
+ |
|
| 343 |
+ $ docker-machine ip mhs-demo0 |
|
| 344 |
+ |
|
| 345 |
+8. Put the IP address into your web browser. |
|
| 346 |
+ |
|
| 347 |
+ Upon success, the browser should display the web application. |
|
| 340 | 348 |
|
| 341 | 349 |
## Related information |
| 342 | 350 |
|