Jasper van den Bosch Jasper van den Bosch - 11 days ago 8
Python Question

How to bind volumes in docker-py?

I think this used to work up to a few months ago. The regular commandline docker:

>> docker run --name 'mycontainer' -d -v '/new' ubuntu /bin/bash -c 'touch /new/hello.txt'
>> docker run --volumes-from mycontainer ubuntu /bin/bash -c 'ls new'
>> hello.txt


works as expected but I cannot get this to work in docker-py:

from docker import Client #docker-py
import time

docker = Client(base_url='unix://var/run/docker.sock')
response1 = docker.create_container('ubuntu', detach=True, volumes=['/new'],
command="/bin/bash -c 'touch /new/hello.txt'", name='mycontainer2')
docker.start(response1['Id'])
time.sleep(1)
response = docker.create_container('ubuntu',
command="/bin/bash -c 'ls new'",
volumes_from='mycontainer2')
docker.start(response['Id'])
time.sleep(1)
print(docker.logs(response['Id']))


..always tells me that new doesn't exist. How is
volumes-from
supposed to be done with docker-py?

Answer

Starting from docker api version 1.10 volumes-from is an argument to start() instead of create()

Available from docker-py release 0.3.2

Pull request which introduced the change: https://github.com/dotcloud/docker-py/pull/200