mirror of https://github.com/docker/docker-py.git
Merge pull request #133 from namin/network-disabled-opt
Option to disable network when creating container.
This commit is contained in:
commit
2891c63870
|
|
@ -55,7 +55,7 @@ Identical to the `docker cp` command.
|
||||||
c.create_container(image, command=None, hostname=None, user=None,
|
c.create_container(image, command=None, hostname=None, user=None,
|
||||||
detach=False, stdin_open=False, tty=False, mem_limit=0,
|
detach=False, stdin_open=False, tty=False, mem_limit=0,
|
||||||
ports=None, environment=None, dns=None, volumes=None,
|
ports=None, environment=None, dns=None, volumes=None,
|
||||||
volumes_from=None, name=None)
|
volumes_from=None, network_disabled=False, name=None)
|
||||||
```
|
```
|
||||||
|
|
||||||
Creates a container that can then be `start`ed. Parameters are similar
|
Creates a container that can then be `start`ed. Parameters are similar
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,8 @@ class Client(requests.Session):
|
||||||
def _container_config(self, image, command, hostname=None, user=None,
|
def _container_config(self, image, command, hostname=None, user=None,
|
||||||
detach=False, stdin_open=False, tty=False,
|
detach=False, stdin_open=False, tty=False,
|
||||||
mem_limit=0, ports=None, environment=None, dns=None,
|
mem_limit=0, ports=None, environment=None, dns=None,
|
||||||
volumes=None, volumes_from=None):
|
volumes=None, volumes_from=None,
|
||||||
|
network_disabled=False):
|
||||||
if isinstance(command, six.string_types):
|
if isinstance(command, six.string_types):
|
||||||
command = shlex.split(str(command))
|
command = shlex.split(str(command))
|
||||||
if isinstance(environment, dict):
|
if isinstance(environment, dict):
|
||||||
|
|
@ -176,6 +177,7 @@ class Client(requests.Session):
|
||||||
'Image': image,
|
'Image': image,
|
||||||
'Volumes': volumes,
|
'Volumes': volumes,
|
||||||
'VolumesFrom': volumes_from,
|
'VolumesFrom': volumes_from,
|
||||||
|
'NetworkDisabled': network_disabled
|
||||||
}
|
}
|
||||||
|
|
||||||
def _post_json(self, url, data, **kwargs):
|
def _post_json(self, url, data, **kwargs):
|
||||||
|
|
@ -389,11 +391,12 @@ class Client(requests.Session):
|
||||||
def create_container(self, image, command=None, hostname=None, user=None,
|
def create_container(self, image, command=None, hostname=None, user=None,
|
||||||
detach=False, stdin_open=False, tty=False,
|
detach=False, stdin_open=False, tty=False,
|
||||||
mem_limit=0, ports=None, environment=None, dns=None,
|
mem_limit=0, ports=None, environment=None, dns=None,
|
||||||
volumes=None, volumes_from=None, name=None):
|
volumes=None, volumes_from=None,
|
||||||
|
network_disabled=False, name=None):
|
||||||
|
|
||||||
config = self._container_config(
|
config = self._container_config(
|
||||||
image, command, hostname, user, detach, stdin_open, tty, mem_limit,
|
image, command, hostname, user, detach, stdin_open, tty, mem_limit,
|
||||||
ports, environment, dns, volumes, volumes_from
|
ports, environment, dns, volumes, volumes_from, network_disabled
|
||||||
)
|
)
|
||||||
return self.create_container_from_config(config, name)
|
return self.create_container_from_config(config, name)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -180,7 +180,7 @@ class DockerClientTest(unittest.TestCase):
|
||||||
{"Tty": false, "Image": "busybox", "Cmd": ["true"],
|
{"Tty": false, "Image": "busybox", "Cmd": ["true"],
|
||||||
"AttachStdin": false, "Memory": 0,
|
"AttachStdin": false, "Memory": 0,
|
||||||
"AttachStderr": true, "AttachStdout": true,
|
"AttachStderr": true, "AttachStdout": true,
|
||||||
"OpenStdin": false}'''))
|
"OpenStdin": false, "NetworkDisabled": false}'''))
|
||||||
self.assertEqual(args[1]['headers'],
|
self.assertEqual(args[1]['headers'],
|
||||||
{'Content-Type': 'application/json'})
|
{'Content-Type': 'application/json'})
|
||||||
|
|
||||||
|
|
@ -203,7 +203,8 @@ class DockerClientTest(unittest.TestCase):
|
||||||
"Cmd": ["ls", "/mnt"], "AttachStdin": false,
|
"Cmd": ["ls", "/mnt"], "AttachStdin": false,
|
||||||
"Volumes": {"/mnt": {}}, "Memory": 0,
|
"Volumes": {"/mnt": {}}, "Memory": 0,
|
||||||
"AttachStderr": true,
|
"AttachStderr": true,
|
||||||
"AttachStdout": true, "OpenStdin": false}'''))
|
"AttachStdout": true, "OpenStdin": false,
|
||||||
|
"NetworkDisabled": false}'''))
|
||||||
self.assertEqual(args[1]['headers'],
|
self.assertEqual(args[1]['headers'],
|
||||||
{'Content-Type': 'application/json'})
|
{'Content-Type': 'application/json'})
|
||||||
|
|
||||||
|
|
@ -227,7 +228,8 @@ class DockerClientTest(unittest.TestCase):
|
||||||
"3333": {}
|
"3333": {}
|
||||||
},
|
},
|
||||||
"AttachStderr": true,
|
"AttachStderr": true,
|
||||||
"AttachStdout": true, "OpenStdin": false}'''))
|
"AttachStdout": true, "OpenStdin": false,
|
||||||
|
"NetworkDisabled": false}'''))
|
||||||
self.assertEqual(args[1]['headers'],
|
self.assertEqual(args[1]['headers'],
|
||||||
{'Content-Type': 'application/json'})
|
{'Content-Type': 'application/json'})
|
||||||
|
|
||||||
|
|
@ -246,7 +248,7 @@ class DockerClientTest(unittest.TestCase):
|
||||||
{"Tty": false, "Image": "busybox", "Cmd": ["true"],
|
{"Tty": false, "Image": "busybox", "Cmd": ["true"],
|
||||||
"AttachStdin": false, "Memory": 0,
|
"AttachStdin": false, "Memory": 0,
|
||||||
"AttachStderr": true, "AttachStdout": true,
|
"AttachStderr": true, "AttachStdout": true,
|
||||||
"OpenStdin": false}'''))
|
"OpenStdin": false, "NetworkDisabled": false}'''))
|
||||||
self.assertEqual(args[1]['headers'],
|
self.assertEqual(args[1]['headers'],
|
||||||
{'Content-Type': 'application/json'})
|
{'Content-Type': 'application/json'})
|
||||||
self.assertEqual(args[1]['params'], {'name': 'marisa-kirisame'})
|
self.assertEqual(args[1]['params'], {'name': 'marisa-kirisame'})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue