Add entrypoint option to create_container

This commit is contained in:
Ben Firshman 2014-01-19 16:34:44 +00:00
parent 477831334c
commit 8e8b355acd
3 changed files with 30 additions and 5 deletions

View File

@ -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)
```
Creates a container that can then be `start`ed. Parameters are similar

View File

@ -122,7 +122,7 @@ 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):
if isinstance(command, six.string_types):
command = shlex.split(str(command))
if isinstance(environment, dict):
@ -175,7 +175,8 @@ class Client(requests.Session):
'Image': image,
'Volumes': volumes,
'VolumesFrom': volumes_from,
'NetworkDisabled': network_disabled
'NetworkDisabled': network_disabled,
'Entrypoint': entrypoint
}
def _post_json(self, url, data, **kwargs):
@ -406,11 +407,12 @@ 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):
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
)
return self.create_container_from_config(config, name)

View File

@ -229,6 +229,28 @@ 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_named_container(self):
try:
self.client.create_container('busybox', 'true',