如何在docker-py中绑定卷? [英] How to bind volumes in docker-py?

查看:129
本文介绍了如何在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

按预期工作,但我无法在docker-py中工作:

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']))

..总是告诉我新的不存在. volumes-from应该如何用docker-py完成?

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

推荐答案

以下是进行卷绑定的当前工作方式:

Below is the current working way to do 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'))

这篇关于如何在docker-py中绑定卷?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆