python - How to bind volumes in docker-py? -
i think used work few months ago. 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 expected cannot 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 new doesn't exist. how volumes-from
supposed done docker-py?
below current working way volume bindings:
volumes= ['/host_location'] volume_bindings = { '/host_location': { 'bind': '/container_location', 'mode': 'rw', }, } host_config = client.create_host_config( binds=volume_bindings ) container = client.create_container( image='josepainumkal/vwadaptor:jose_toolui', name=container_name, volumes=volumes, host_config=host_config, ) response = client.start(container=container.get('id'))
Comments
Post a Comment