mirror of https://github.com/docker/docker-py.git
Add working_dir option to create_container
This commit is contained in:
parent
ab2f7a5e38
commit
4bc5d27e51
|
@ -56,7 +56,7 @@ 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,
|
||||
entrypoint=None, cpu_shares=None)
|
||||
entrypoint=None, cpu_shares=None, working_dir=None)
|
||||
```
|
||||
|
||||
Creates a container that can then be `start`ed. Parameters are similar
|
||||
|
|
|
@ -123,7 +123,7 @@ class Client(requests.Session):
|
|||
mem_limit=0, ports=None, environment=None, dns=None,
|
||||
volumes=None, volumes_from=None,
|
||||
network_disabled=False, entrypoint=None,
|
||||
cpu_shares=None):
|
||||
cpu_shares=None, working_dir=None):
|
||||
if isinstance(command, six.string_types):
|
||||
command = shlex.split(str(command))
|
||||
if isinstance(environment, dict):
|
||||
|
@ -178,7 +178,8 @@ class Client(requests.Session):
|
|||
'VolumesFrom': volumes_from,
|
||||
'NetworkDisabled': network_disabled,
|
||||
'Entrypoint': entrypoint,
|
||||
'CpuShares': cpu_shares
|
||||
'CpuShares': cpu_shares,
|
||||
'WorkingDir': working_dir
|
||||
}
|
||||
|
||||
def _post_json(self, url, data, **kwargs):
|
||||
|
@ -410,12 +411,12 @@ class Client(requests.Session):
|
|||
mem_limit=0, ports=None, environment=None, dns=None,
|
||||
volumes=None, volumes_from=None,
|
||||
network_disabled=False, name=None, entrypoint=None,
|
||||
cpu_shares=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,
|
||||
entrypoint, cpu_shares
|
||||
entrypoint, cpu_shares, working_dir
|
||||
)
|
||||
return self.create_container_from_config(config, name)
|
||||
|
||||
|
|
|
@ -273,6 +273,28 @@ class DockerClientTest(unittest.TestCase):
|
|||
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