mirror of https://github.com/docker/compose.git
add net param support
Signed-off-by: Peter Flood <info@whywouldwe.com>
This commit is contained in:
parent
1e7e8202af
commit
6b8044e92c
|
@ -59,3 +59,5 @@ environment:
|
|||
RACK_ENV: development
|
||||
```
|
||||
|
||||
-- Networking mode. Use the same values as the docker client --net parameter
|
||||
net: "host"
|
||||
|
|
|
@ -679,7 +679,7 @@ class Client(requests.Session):
|
|||
True)
|
||||
|
||||
def start(self, container, binds=None, volumes_from=None, port_bindings=None,
|
||||
lxc_conf=None, publish_all_ports=False, links=None, privileged=False):
|
||||
lxc_conf=None, publish_all_ports=False, links=None, privileged=False, network_mode=None):
|
||||
if isinstance(container, dict):
|
||||
container = container.get('Id')
|
||||
|
||||
|
@ -726,6 +726,9 @@ class Client(requests.Session):
|
|||
|
||||
start_config['Privileged'] = privileged
|
||||
|
||||
if network_mode:
|
||||
start_config['NetworkMode'] = network_mode
|
||||
|
||||
url = self._url("/containers/{0}/start".format(container))
|
||||
res = self._post_json(url, data=start_config)
|
||||
self._raise_for_status(res)
|
||||
|
|
|
@ -11,7 +11,7 @@ from .progress_stream import stream_output, StreamOutputError
|
|||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
DOCKER_CONFIG_KEYS = ['image', 'command', 'hostname', 'user', 'detach', 'stdin_open', 'tty', 'mem_limit', 'ports', 'environment', 'dns', 'volumes', 'volumes_from', 'entrypoint', 'privileged']
|
||||
DOCKER_CONFIG_KEYS = ['image', 'command', 'hostname', 'user', 'detach', 'stdin_open', 'tty', 'mem_limit', 'ports', 'environment', 'dns', 'volumes', 'volumes_from', 'entrypoint', 'privileged', 'net']
|
||||
DOCKER_CONFIG_HINTS = {
|
||||
'link' : 'links',
|
||||
'port' : 'ports',
|
||||
|
@ -229,6 +229,7 @@ class Service(object):
|
|||
}
|
||||
|
||||
privileged = options.get('privileged', False)
|
||||
net = options.get('net', 'bridge')
|
||||
|
||||
container.start(
|
||||
links=self._get_links(link_to_self=override_options.get('one_off', False)),
|
||||
|
@ -236,6 +237,7 @@ class Service(object):
|
|||
binds=volume_bindings,
|
||||
volumes_from=volumes_from,
|
||||
privileged=privileged,
|
||||
network_mode=net,
|
||||
)
|
||||
return container
|
||||
|
||||
|
@ -297,6 +299,10 @@ class Service(object):
|
|||
if 'privileged' in container_options:
|
||||
del container_options['privileged']
|
||||
|
||||
# net is only required for starting containers, not for creating them
|
||||
if 'net' in container_options:
|
||||
del container_options['net']
|
||||
|
||||
return container_options
|
||||
|
||||
def build(self):
|
||||
|
|
|
@ -253,3 +253,18 @@ class ServiceTest(DockerClientTestCase):
|
|||
self.assertEqual(len(containers), 2)
|
||||
for container in containers:
|
||||
self.assertEqual(list(container.inspect()['HostConfig']['PortBindings'].keys()), ['8000/tcp'])
|
||||
|
||||
def test_network_mode_none(self):
|
||||
service = self.create_service('web', net='none')
|
||||
container = service.start_container().inspect()
|
||||
self.assertEqual(container['HostConfig']['NetworkMode'], 'none')
|
||||
|
||||
def test_network_mode_bridged(self):
|
||||
service = self.create_service('web', net='bridge')
|
||||
container = service.start_container().inspect()
|
||||
self.assertEqual(container['HostConfig']['NetworkMode'], 'bridge')
|
||||
|
||||
def test_network_mode_host(self):
|
||||
service = self.create_service('web', net='host')
|
||||
container = service.start_container().inspect()
|
||||
self.assertEqual(container['HostConfig']['NetworkMode'], 'host')
|
||||
|
|
Loading…
Reference in New Issue