Browse code

Docs cleanup for networking features added in v1.10

Signed-off-by: Madhu Venugopal <madhu@docker.com>

Madhu Venugopal authored on 2016/02/01 04:13:25
Showing 6 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,138 @@
0
+<!--[metadata]>
1
+title = "Configure container DNS in user-defined networks"
2
+description = "Learn how to configure DNS in user-defined networks"
3
+keywords = ["docker, DNS, network"]
4
+[menu.main]
5
+parent = "smn_networking"
6
+<![end-metadata]-->
7
+
8
+# Embedded DNS server in user-defined networks
9
+
10
+The information in this section covers the embedded DNS server operation for
11
+containers in user-defined networks. DNS lookup for containers connected to
12
+user-defined networks works differently compared to the containers connected
13
+to `default bridge` network.
14
+
15
+> **Note**: In order to maintain backward compatibility, the DNS configuration
16
+> in `default bridge` network is retained with no behaviorial change.
17
+> Please refer to the [DNS in default bridge network](default_network/configure-dns.md)
18
+> for more information on DNS configuration in the `default bridge` network.
19
+
20
+As of Docker 1.10, the docker daemon implements an embedded DNS server which
21
+provides built-in service discovery for any container created with a valid
22
+`name` or `net-alias` or aliased by `link`. The exact details of how Docker
23
+manages the DNS configurations inside the container can change from one Docker
24
+version to the next. So you should not assume the way the files such as
25
+`/etc/hosts`, `/etc/resolv.conf` are managed inside the containers and leave
26
+the files alone and use the following Docker options instead.
27
+
28
+Various container options that affect container domain name services.
29
+
30
+<table>
31
+  <tr>
32
+    <td>
33
+    <p>
34
+    <code>--name=CONTAINER-NAME</code>
35
+    </p>
36
+    </td>
37
+    <td>
38
+    <p>
39
+     Container name configured using <code>--name</code> is used to discover a container within
40
+     an user-defined docker network. The embedded DNS server maintains the mapping between
41
+     the container name and its IP address (on the network the container is connected to).
42
+    </p>
43
+    </td>
44
+  </tr>
45
+  <tr>
46
+    <td>
47
+    <p>
48
+    <code>--net-alias=ALIAS</code>
49
+    </p>
50
+    </td>
51
+    <td>
52
+    <p>
53
+     In addition to <code>--name</code> as described above, a container is discovered by one or more 
54
+     of its configured <code>--net-alias</code> (or <code>--alias</code> in <code>docker network connect</code> command)
55
+     within the user-defined network. The embedded DNS server maintains the mapping between
56
+     all of the container aliases and its IP address on a specific user-defined network.
57
+     A container can have different aliases in different networks by using the <code>--alias</code>
58
+     option in <code>docker network connect</code> command.
59
+    </p>
60
+    </td>
61
+  </tr>
62
+  <tr>
63
+    <td>
64
+    <p>
65
+    <code>--link=CONTAINER_NAME:ALIAS</code>
66
+    </p>
67
+    </td>
68
+    <td>
69
+    <p>
70
+      Using this option as you <code>run</code> a container gives the embedded DNS
71
+      an extra entry named <code>ALIAS</code> that points to the IP address
72
+      of the container identified by <code>CONTAINER_NAME</code>. When using <code>--link</code>
73
+      the embedded DNS will guarantee that localized lookup result only on that
74
+      container where the <code>--link</code> is used. This lets processes inside the new container 
75
+      connect to container without without having to know its name or IP.
76
+    </p>
77
+    </td>
78
+  </tr>
79
+  <tr>
80
+    <td><p>
81
+    <code>--dns=[IP_ADDRESS...]</code>
82
+    </p></td>
83
+    <td><p>
84
+     The IP addresses passed via the <code>--dns</code> option is used by the embedded DNS
85
+     server to forward the DNS query if embedded DNS server is unable to resolve a name
86
+     resolution request from the containers.
87
+     These  <code>--dns</code> IP addresses are managed by the embedded DNS server and
88
+     will not be updated in the container's <code>/etc/resolv.conf</code> file.
89
+  </tr>
90
+  <tr>
91
+    <td><p>
92
+    <code>--dns-search=DOMAIN...</code>
93
+    </p></td>
94
+    <td><p>
95
+    Sets the domain names that are searched when a bare unqualified hostname is
96
+    used inside of the container. These <code>--dns-search</code> options are managed by the
97
+    embedded DNS server and will not be updated in the container's <code>/etc/resolv.conf</code> file.
98
+    When a container process attempts to access <code>host</code> and the search
99
+    domain <code>example.com</code> is set, for instance, the DNS logic will not only
100
+    look up <code>host</code> but also <code>host.example.com</code>.
101
+    </p>
102
+    </td>
103
+  </tr>
104
+  <tr>
105
+    <td><p>
106
+    <code>--dns-opt=OPTION...</code>
107
+    </p></td>
108
+    <td><p>
109
+      Sets the options used by DNS resolvers. These options are managed by the embedded
110
+      DNS server and will not be updated in the container's <code>/etc/resolv.conf</code> file.
111
+    </p>
112
+    <p>
113
+    See documentation for <code>resolv.conf</code> for a list of valid options
114
+    </p></td>
115
+  </tr>
116
+</table>
117
+
118
+
119
+In the absence of the `--dns=IP_ADDRESS...`, `--dns-search=DOMAIN...`, or
120
+`--dns-opt=OPTION...` options, Docker uses the `/etc/resolv.conf` of the
121
+host machine (where the `docker` daemon runs). While doing so the daemon
122
+filters out all localhost IP address `nameserver` entries from the host's
123
+original file.
124
+
125
+Filtering is necessary because all localhost addresses on the host are
126
+unreachable from the container's network. After this filtering, if there are
127
+no more `nameserver` entries left in the container's `/etc/resolv.conf` file,
128
+the daemon adds public Google DNS nameservers (8.8.8.8 and 8.8.4.4) to the
129
+container's DNS configuration. If IPv6 is enabled on the daemon, the public
130
+IPv6 Google DNS nameservers will also be added (2001:4860:4860::8888 and
131
+2001:4860:4860::8844).
132
+
133
+> **Note**: If you need access to a host's localhost resolver, you must modify
134
+> your DNS service on the host to listen on a non-localhost address that is
135
+> reachable from within the container.
... ...
@@ -14,7 +14,7 @@ The information in this section explains configuring container DNS within
14 14
 the Docker default bridge. This is a `bridge` network named `bridge` created
15 15
 automatically when you install Docker.  
16 16
 
17
-**Note**: The [Docker networks feature](../dockernetworks.md) allows you to create user-defined networks in addition to the default bridge network.
17
+> **Note**: The [Docker networks feature](../dockernetworks.md) allows you to create user-defined networks in addition to the default bridge network. Please refer to the [Docker Embedded DNS](../configure-dns.md) section for more information on DNS configurations in user-defined networks.
18 18
 
19 19
 How can Docker supply each container with a hostname and DNS configuration, without having to build a custom image with the hostname written inside?  Its trick is to overlay three crucial `/etc` files inside the container with virtual files where it can write fresh information.  You can see this by running `mount` inside a container:
20 20
 
... ...
@@ -11,7 +11,7 @@ weight=-2
11 11
 
12 12
 # Legacy container links
13 13
 
14
-The information in this section explains legacy container links within the Docker default bridge. This is a `bridge` network named `bridge` created automatically when you install Docker.  
14
+The information in this section explains legacy container links within the Docker default bridge. This is a `bridge` network named `bridge` created automatically when you install Docker. 
15 15
 
16 16
 Before the [Docker networks feature](../dockernetworks.md), you could use the
17 17
 Docker link feature to allow containers to discover each other and securely
... ...
@@ -95,6 +95,12 @@ configurations. For example, if you've bound the container port to the
95 95
 
96 96
 ## Connect with the linking system
97 97
 
98
+> **Note**:
99
+> This section covers the legacy link feature in the default `bridge` network.
100
+> Please refer to [linking containers in user-defined networks]
101
+> (../work-with-networks.md#linking-containers-in-user-defined-networks)
102
+> for more information on links in user-defined networks.
103
+
98 104
 Network port mappings are not the only way Docker containers can connect to one
99 105
 another. Docker also has a linking system that allows you to link multiple
100 106
 containers together and send connection information from one to another. When
... ...
@@ -284,7 +284,7 @@ The default `docker0` bridge network supports the use of port mapping and  `dock
284 284
 ## User-defined networks
285 285
 
286 286
 You can create your own user-defined networks that better isolate containers.
287
-Docker provides some default **network drivers** for use creating these
287
+Docker provides some default **network drivers** for creating these
288 288
 networks. You can create a new **bridge network** or **overlay network**. You
289 289
 can also create a **network plugin** or **remote network**  written to your own
290 290
 specifications.
... ...
@@ -439,6 +439,10 @@ Docker Engine for use with `overlay` network. There are two options to set:
439 439
         <td><pre>--cluster-advertise=HOST_IP|HOST_IFACE:PORT</pre></td>
440 440
         <td>The IP address or interface of the HOST used for clustering.</td>
441 441
     </tr>
442
+    <tr>
443
+        <td><pre>--cluster-store-opt=KEY-VALUE OPTIONS</pre></td>
444
+        <td>Options such as TLS certificate or tuning discovery Timers</td>
445
+    </tr>
442 446
     </tbody>
443 447
 </table>
444 448
 
... ...
@@ -485,17 +489,28 @@ networks can include features not present in Docker's default networks. For more
485 485
 information on writing plugins, see [Extending Docker](../../extend/index.md) and
486 486
 [Writing a network driver plugin](../../extend/plugins_network.md).
487 487
 
488
-## Legacy links
488
+### Docker embedded DNS server
489
+
490
+Docker daemon runs an embedded DNS server to provide automatic service discovery
491
+for containers connected to user defined networks. Name resolution requests from
492
+the containers are handled first by the embedded DNS server. If the embedded DNS
493
+server is unable to resolve the request it will be forwarded to any external DNS
494
+servers configured for the container. To facilitate this when the container is
495
+created, only the embedded DNS server reachable at `127.0.0.11` will be listed
496
+in the container's `resolv.conf` file. More information on embedded DNS server on
497
+user-defined networks can be found in the [embedded DNS server in user-defined networks]
498
+(configure-dns.md)
499
+
500
+## Links
489 501
 
490 502
 Before the Docker network feature, you could use the Docker link feature to
491
-allow containers to discover each other and securely transfer information about
492
-one container to another container. With the introduction of Docker networks,
493
-you can still create links but they are only supported on the default `bridge`
494
-network named `bridge` and appearing in your network stack as `docker0`.
495
-
496
-While links are still supported in this limited capacity, you should avoid them
497
-in preference of Docker networks. The link feature is expected to be deprecated
498
-and removed in a future release.
503
+allow containers to discover each other.  With the introduction of Docker networks,
504
+containers can be discovered by its name automatically. But you can still create
505
+links but they behave differently when used in the default `docker0` bridge network
506
+compared to user-defined networks. For more information, please refer to
507
+[Legacy Links](default_network/dockerlinks.md) for link feature in default `bridge` network
508
+and the [linking containers in user-defined networks](work-with-networks.md#linking-containers-in-user-defined-networks) for links
509
+functionality in user-defined networks.
499 510
 
500 511
 ## Related information
501 512
 
... ...
@@ -158,10 +158,16 @@ To create an overlay network
158 158
 
159 159
 3. Create your `overlay` network.
160 160
 
161
-		$ docker network create --driver overlay my-net
161
+		$ docker network create --driver overlay --subnet=10.0.9.0/24 my-net
162 162
 
163 163
 	You only need to create the network on a single host in the cluster. In this case, you used the Swarm master but you could easily have run it on any host in the cluster.
164 164
 
165
+> **Note** : It is highly recommended to use the `--subnet` option when creating
166
+> a network. If the `--subnet` is not specified, the docker daemon automatically
167
+> chooses and assigns a subnet for the network and it could overlap with another subnet
168
+> in your infrastructure that is not managed by docker. Such overlaps can cause
169
+> connectivity issues or failures when containers are connected to that network.
170
+
165 171
 4. Check that the network is running:
166 172
 
167 173
 		$ docker network ls
... ...
@@ -308,41 +314,9 @@ to have external connectivity outside of their cluster.
308 308
 
309 309
 ## Step 6: Extra Credit with Docker Compose
310 310
 
311
-You can try starting a second network on your existing Swarm cluster using Docker Compose.
312
-
313
-1. If you haven't already, install Docker Compose.
314
-
315
-2. Change your environment to the Swarm master.
316
-
317
-		$ eval $(docker-machine env --swarm mhs-demo0)
318
-
319
-3. Create a `docker-compose.yml` file.
320
-
321
-4. Add the following content to the file.
322
-
323
-		web:
324
-			image: bfirsh/compose-mongodb-demo
325
-			environment:
326
-				- "MONGO_HOST=counter_mongo_1"
327
-				- "constraint:node==mhs-demo0"
328
-			ports:
329
-				- "80:5000"
330
-		mongo:
331
-			image: mongo
332
-
333
-5. Save and close the file.
334
-
335
-6. Start the application with Compose.
336
-
337
-		$ docker-compose --x-networking --project-name=counter up -d
338
-
339
-7. Get the Swarm master's IP address.
340
-
341
-		$ docker-machine ip mhs-demo0
342
-
343
-8. Put the IP address into your web browser.
344
-
345
-	Upon success, the browser should display the web application.
311
+Please refer to the Networking feature introduced in [Compose V2 format]
312
+(https://docs.docker.com/compose/networking/) and execute the
313
+multi-host networking scenario in the Swarm cluster used above.
346 314
 
347 315
 ## Related information
348 316
 
... ...
@@ -79,7 +79,13 @@ management that can assist your implementation.
79 79
 When you create a network, Engine creates a non-overlapping subnetwork for the
80 80
 network by default. You can override this default and specify a subnetwork
81 81
 directly using the the `--subnet` option. On a `bridge` network you can only
82
-create a single subnet. An `overlay` network supports multiple subnets.
82
+specify a single subnet. An `overlay` network supports multiple subnets.
83
+
84
+> **Note** : It is highly recommended to use the `--subnet` option while creating
85
+> a network. If the `--subnet` is not specified, the docker daemon automatically
86
+> chooses and assigns a subnet for the network and it could overlap with another subnet
87
+> in your infrastructure that is not managed by docker. Such overlaps can cause
88
+> connectivity issues or failures when containers are connected to that network.
83 89
 
84 90
 In addition to the `--subnetwork` option, you also specify the `--gateway` `--ip-range` and `--aux-address` options.
85 91
 
... ...
@@ -778,6 +784,25 @@ round-trip min/avg/max = 0.119/0.146/0.174 ms
778 778
 / #
779 779
 ```
780 780
 
781
+There are certain scenarios such as ungraceful docker daemon restarts in multi-host network,
782
+where the daemon is unable to cleanup stale connectivity endpoints. Such stale endpoints
783
+may cause an error `container already connected to network` when a new container is
784
+connected to that network with the same name as the stale endpoint. In order to cleanup
785
+these stale endpoints, first remove the container and force disconnect 
786
+(`docker network disconnect -f`)  the endpoint from the network. Once the endpoint is 
787
+cleaned up, the container can be connected to the network.
788
+
789
+```
790
+$ docker run -d --name redis_db --net multihost redis
791
+ERROR: Cannot start container bc0b19c089978f7845633027aa3435624ca3d12dd4f4f764b61eac4c0610f32e: container already connected to network multihost
792
+
793
+$ docker rm -f redis_db
794
+$ docker network disconnect -f multihost redis_db
795
+
796
+$ docker run -d --name redis_db --net multihost redis
797
+7d986da974aeea5e9f7aca7e510bdb216d58682faa83a9040c2f2adc0544795a
798
+```
799
+
781 800
 ## Remove a network
782 801
 
783 802
 When all the containers in a network are stopped or disconnected, you can remove a network.