Implement network_mode in v2

Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
Aanand Prasad 2016-01-25 12:45:30 +00:00
commit e566a4dc1c
16 changed files with 405 additions and 87 deletions

View file

@ -437,14 +437,29 @@ Specify logging options as key-value pairs. An example of `syslog` options:
### net
> [Version 1 file format](#version-1) only. In version 2, use
> [networks](#networks).
> [network_mode](#network_mode).
Networking mode. Use the same values as the docker client `--net` parameter.
Network mode. Use the same values as the docker client `--net` parameter.
The `container:...` form can take a service name instead of a container name or
id.
net: "bridge"
net: "none"
net: "container:[name or id]"
net: "host"
net: "none"
net: "container:[service name or container name/id]"
### network_mode
> [Version 2 file format](#version-1) only. In version 1, use [net](#net).
Network mode. Use the same values as the docker client `--net` parameter, plus
the special form `service:[service name]`.
network_mode: "bridge"
network_mode: "host"
network_mode: "none"
network_mode: "service:[service name]"
network_mode: "container:[container name/id]"
### networks
@ -457,8 +472,8 @@ Networks to join, referencing entries under the
- some-network
- other-network
The values `bridge`, `host` and `none` can also be used, and are equivalent to
`net: "bridge"`, `net: "host"` or `net: "none"` in version 1.
The value `bridge` can also be used to make containers join the pre-defined
`bridge` network.
There is no equivalent to `net: "container:[name or id]"`.
@ -918,16 +933,22 @@ It's more complicated if you're using particular configuration features:
your service's containers to an
[external network](networking.md#using-a-pre-existing-network).
- `net`: If you're using `host`, `bridge` or `none`, this is now replaced by
`networks`:
- `net`: This is now replaced by [network_mode](#network_mode):
net: host -> networks: ["host"]
net: bridge -> networks: ["bridge"]
net: none -> networks: ["none"]
net: host -> network_mode: host
net: bridge -> network_mode: bridge
net: none -> network_mode: none
If you're using `net: "container:<name>"`, there is no equivalent to this in
version 2 - you should use [Docker networks](networking.md) for
communication instead.
If you're using `net: "container:[service name]"`, you must now use
`network_mode: "service:[service name]"` instead.
net: "container:web" -> network_mode: "service:web"
If you're using `net: "container:[container name/id]"`, the value does not
need to change.
net: "container:cont-name" -> network_mode: "container:cont-name"
net: "container:abc12345" -> network_mode: "container:abc12345"
## Variable substitution

View file

@ -144,15 +144,3 @@ If you want your containers to join a pre-existing network, use the [`external`
name: my-pre-existing-network
Instead of attemping to create a network called `[projectname]_default`, Compose will look for a network called `my-pre-existing-network` and connect your app's containers to it.
## Custom container network modes
The `docker` CLI command allows you to specify a custom network mode for a container with the `--net` option - for example, `--net=host` specifies that the container should use the same network namespace as the Docker host, and `--net=none` specifies that it should have no networking capabilities.
To make use of this in Compose, specify a `networks` list with a single item `host`, `bridge` or `none`:
app:
build: ./app
networks: ["host"]
There is no equivalent to `--net=container:CONTAINER_NAME` in the v2 Compose file format. You should instead use networks to enable communication.