mirror of https://github.com/docker/docker-py.git
Merge pull request #144 from bfirsh/add-missing-create-container-options
Add entrypoint, cpu_shares and working_dir options to create_container
This commit is contained in:
commit
236bb5f09e
|
@ -55,7 +55,8 @@ Identical to the `docker cp` command.
|
|||
c.create_container(image, command=None, hostname=None, user=None,
|
||||
detach=False, stdin_open=False, tty=False, mem_limit=0,
|
||||
ports=None, environment=None, dns=None, volumes=None,
|
||||
volumes_from=None, network_disabled=False, name=None)
|
||||
volumes_from=None, network_disabled=False, name=None,
|
||||
entrypoint=None, cpu_shares=None, working_dir=None)
|
||||
```
|
||||
|
||||
Creates a container that can then be `start`ed. Parameters are similar
|
||||
|
|
|
@ -122,7 +122,8 @@ class Client(requests.Session):
|
|||
detach=False, stdin_open=False, tty=False,
|
||||
mem_limit=0, ports=None, environment=None, dns=None,
|
||||
volumes=None, volumes_from=None,
|
||||
network_disabled=False):
|
||||
network_disabled=False, entrypoint=None,
|
||||
cpu_shares=None, working_dir=None):
|
||||
if isinstance(command, six.string_types):
|
||||
command = shlex.split(str(command))
|
||||
if isinstance(environment, dict):
|
||||
|
@ -175,7 +176,10 @@ class Client(requests.Session):
|
|||
'Image': image,
|
||||
'Volumes': volumes,
|
||||
'VolumesFrom': volumes_from,
|
||||
'NetworkDisabled': network_disabled
|
||||
'NetworkDisabled': network_disabled,
|
||||
'Entrypoint': entrypoint,
|
||||
'CpuShares': cpu_shares,
|
||||
'WorkingDir': working_dir
|
||||
}
|
||||
|
||||
def _post_json(self, url, data, **kwargs):
|
||||
|
@ -406,11 +410,13 @@ class Client(requests.Session):
|
|||
detach=False, stdin_open=False, tty=False,
|
||||
mem_limit=0, ports=None, environment=None, dns=None,
|
||||
volumes=None, volumes_from=None,
|
||||
network_disabled=False, name=None):
|
||||
network_disabled=False, name=None, entrypoint=None,
|
||||
cpu_shares=None, working_dir=None):
|
||||
|
||||
config = self._container_config(
|
||||
image, command, hostname, user, detach, stdin_open, tty, mem_limit,
|
||||
ports, environment, dns, volumes, volumes_from, network_disabled
|
||||
ports, environment, dns, volumes, volumes_from, network_disabled,
|
||||
entrypoint, cpu_shares, working_dir
|
||||
)
|
||||
return self.create_container_from_config(config, name)
|
||||
|
||||
|
|
|
@ -229,6 +229,72 @@ class DockerClientTest(unittest.TestCase):
|
|||
self.assertEqual(args[1]['headers'],
|
||||
{'Content-Type': 'application/json'})
|
||||
|
||||
def test_create_container_with_entrypoint(self):
|
||||
try:
|
||||
self.client.create_container('busybox', 'hello',
|
||||
entrypoint='cowsay')
|
||||
except Exception as e:
|
||||
self.fail('Command should not raise exception: {0}'.format(e))
|
||||
|
||||
args = fake_request.call_args
|
||||
self.assertEqual(args[0][0],
|
||||
'unix://var/run/docker.sock/v1.6/containers/create')
|
||||
self.assertEqual(json.loads(args[1]['data']),
|
||||
json.loads('''
|
||||
{"Tty": false, "Image": "busybox",
|
||||
"Cmd": ["hello"], "AttachStdin": false,
|
||||
"Memory": 0,
|
||||
"AttachStderr": true,
|
||||
"AttachStdout": true, "OpenStdin": false,
|
||||
"NetworkDisabled": false,
|
||||
"Entrypoint": "cowsay"}'''))
|
||||
self.assertEqual(args[1]['headers'],
|
||||
{'Content-Type': 'application/json'})
|
||||
|
||||
def test_create_container_with_cpu_shares(self):
|
||||
try:
|
||||
self.client.create_container('busybox', 'ls',
|
||||
cpu_shares=5)
|
||||
except Exception as e:
|
||||
self.fail('Command should not raise exception: {0}'.format(e))
|
||||
|
||||
args = fake_request.call_args
|
||||
self.assertEqual(args[0][0],
|
||||
'unix://var/run/docker.sock/v1.6/containers/create')
|
||||
self.assertEqual(json.loads(args[1]['data']),
|
||||
json.loads('''
|
||||
{"Tty": false, "Image": "busybox",
|
||||
"Cmd": ["ls"], "AttachStdin": false,
|
||||
"Memory": 0,
|
||||
"AttachStderr": true,
|
||||
"AttachStdout": true, "OpenStdin": false,
|
||||
"NetworkDisabled": false,
|
||||
"CpuShares": 5}'''))
|
||||
self.assertEqual(args[1]['headers'],
|
||||
{'Content-Type': 'application/json'})
|
||||
|
||||
def test_create_container_with_working_dir(self):
|
||||
try:
|
||||
self.client.create_container('busybox', 'ls',
|
||||
working_dir='/root')
|
||||
except Exception as e:
|
||||
self.fail('Command should not raise exception: {0}'.format(e))
|
||||
|
||||
args = fake_request.call_args
|
||||
self.assertEqual(args[0][0],
|
||||
'unix://var/run/docker.sock/v1.6/containers/create')
|
||||
self.assertEqual(json.loads(args[1]['data']),
|
||||
json.loads('''
|
||||
{"Tty": false, "Image": "busybox",
|
||||
"Cmd": ["ls"], "AttachStdin": false,
|
||||
"Memory": 0,
|
||||
"AttachStderr": true,
|
||||
"AttachStdout": true, "OpenStdin": false,
|
||||
"NetworkDisabled": false,
|
||||
"WorkingDir": "/root"}'''))
|
||||
self.assertEqual(args[1]['headers'],
|
||||
{'Content-Type': 'application/json'})
|
||||
|
||||
def test_create_named_container(self):
|
||||
try:
|
||||
self.client.create_container('busybox', 'true',
|
||||
|
|
Loading…
Reference in New Issue