Browse code

networking.md: Networking between containers works without ip_forward

Docker-DCO-1.1-Signed-off-by: Erik Inge Bolsø <knan@redpill-linpro.com> (github: knan-linpro)

Erik Inge Bolsø authored on 2014/07/31 23:11:51
Showing 1 changed files
... ...
@@ -170,12 +170,41 @@ above, will make `/etc/resolv.conf` inside of each container look like
170 170
 the `/etc/resolv.conf` of the host machine where the `docker` daemon is
171 171
 running.  The options then modify this default configuration.
172 172
 
173
+## Communication between containers and the wider world
174
+
175
+<a name="the-world"></a>
176
+
177
+Whether a container can talk to the world is governed by one main factor.
178
+
179
+Is the host machine willing to forward IP packets?  This is governed
180
+by the `ip_forward` system parameter.  Packets can only pass between
181
+containers if this parameter is `1`.  Usually you will simply leave
182
+the Docker server at its default setting `--ip-forward=true` and
183
+Docker will go set `ip_forward` to `1` for you when the server
184
+starts up.  To check the setting or turn it on manually:
185
+
186
+    # Usually not necessary: turning on forwarding,
187
+    # on the host where your Docker server is running
188
+
189
+    $ cat /proc/sys/net/ipv4/ip_forward
190
+    0
191
+    $ sudo echo 1 > /proc/sys/net/ipv4/ip_forward
192
+    $ cat /proc/sys/net/ipv4/ip_forward
193
+    1
194
+
195
+Many using Docker will want `ip_forward` to be on, to at
196
+least make communication *possible* between containers and
197
+the wider world.
198
+
199
+May also be needed for inter-container communication if you are
200
+in a multiple bridge setup.
201
+
173 202
 ## Communication between containers
174 203
 
175 204
 <a name="between-containers"></a>
176 205
 
177 206
 Whether two containers can communicate is governed, at the operating
178
-system level, by three factors.
207
+system level, by two factors.
179 208
 
180 209
 1.  Does the network topology even connect the containers' network
181 210
     interfaces?  By default Docker will attach all containers to a
... ...
@@ -183,32 +212,14 @@ system level, by three factors.
183 183
     between them.  See the later sections of this document for other
184 184
     possible topologies.
185 185
 
186
-2.  Is the host machine willing to forward IP packets?  This is governed
187
-    by the `ip_forward` system parameter.  Packets can only pass between
188
-    containers if this parameter is `1`.  Usually you will simply leave
189
-    the Docker server at its default setting `--ip-forward=true` and
190
-    Docker will go set `ip_forward` to `1` for you when the server
191
-    starts up.  To check the setting or turn it on manually:
192
-
193
-        # Usually not necessary: turning on forwarding,
194
-        # on the host where your Docker server is running
195
-
196
-        $ cat /proc/sys/net/ipv4/ip_forward
197
-        0
198
-        $ sudo echo 1 > /proc/sys/net/ipv4/ip_forward
199
-        $ cat /proc/sys/net/ipv4/ip_forward
200
-        1
201
-
202
-3.  Do your `iptables` allow this particular connection to be made?
186
+2.  Do your `iptables` allow this particular connection to be made?
203 187
     Docker will never make changes to your system `iptables` rules if
204 188
     you set `--iptables=false` when the daemon starts.  Otherwise the
205 189
     Docker server will add a default rule to the `FORWARD` chain with a
206 190
     blanket `ACCEPT` policy if you retain the default `--icc=true`, or
207 191
     else will set the policy to `DROP` if `--icc=false`.
208 192
 
209
-Nearly everyone using Docker will want `ip_forward` to be on, to at
210
-least make communication *possible* between containers.  But it is a
211
-strategic question whether to leave `--icc=true` or change it to
193
+It is a strategic question whether to leave `--icc=true` or change it to
212 194
 `--icc=false` (on Ubuntu, by editing the `DOCKER_OPTS` variable in
213 195
 `/etc/default/docker` and restarting the Docker server) so that
214 196
 `iptables` will protect other containers — and the main host — from