mirror of https://github.com/docker/docker-py.git
Added ability to create binds when starting a container.
This commit is contained in:
parent
7f458a3232
commit
c2a145c2d8
|
@ -280,10 +280,19 @@ class Client(requests.Session):
|
|||
return self._result(self.get(self._url("/images/search"),
|
||||
params={'term': term}), True)
|
||||
|
||||
def start(self, *args):
|
||||
def start(self, *args, **kwargs):
|
||||
start_config = {}
|
||||
binds = kwargs.pop('binds', '')
|
||||
if binds:
|
||||
bind_pairs = ['{0}:{1}'.format(host, dest) for host, dest in binds.items()]
|
||||
start_config = {
|
||||
'Binds': bind_pairs,
|
||||
}
|
||||
|
||||
for name in args:
|
||||
url = self._url("/containers/{0}/start".format(name))
|
||||
self.post(url, None)
|
||||
self.post_json(
|
||||
url, start_config, headers={"Content-Type":"application/json"})
|
||||
|
||||
def stop(self, *args, **kwargs):
|
||||
params = {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import os
|
||||
import unittest
|
||||
import time
|
||||
|
||||
import docker
|
||||
|
||||
|
@ -97,6 +97,27 @@ class TestCreateContainer(BaseTestCase):
|
|||
self.assertIn('Id', res)
|
||||
self.tmp_containers.append(res['Id'])
|
||||
|
||||
class TestCreateContainerWithBinds(BaseTestCase):
|
||||
def runTest(self):
|
||||
mount_dest = '/mnt'
|
||||
mount_origin = os.getcwd()
|
||||
|
||||
filename = 'shared.txt'
|
||||
shared_file = os.path.join(mount_origin, filename)
|
||||
|
||||
with open(shared_file, 'w'):
|
||||
container = self.client.create_container('busybox',
|
||||
['ls', mount_dest], volumes={mount_dest: {}})
|
||||
container_id = container['Id']
|
||||
self.client.start(container_id, binds={mount_origin: mount_dest})
|
||||
self.tmp_containers.append(container_id)
|
||||
exitcode = self.client.wait(container_id)
|
||||
self.assertEqual(exitcode, 0)
|
||||
logs = self.client.logs(container_id)
|
||||
|
||||
os.unlink(shared_file)
|
||||
self.assertIn(filename, logs)
|
||||
|
||||
class TestStartContainer(BaseTestCase):
|
||||
def runTest(self):
|
||||
res = self.client.create_container('busybox', 'true')
|
||||
|
@ -297,4 +318,4 @@ class TestRunShlex(BaseTestCase):
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in New Issue