gpt4 book ai didi

python - 如何在 docker-py 中绑定(bind)卷?

转载 作者:太空狗 更新时间:2023-10-30 00:40:46 24 4
gpt4 key购买 nike

我认为这在几个月前还有效。常规命令行 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 中工作:

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 完成?

最佳答案

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

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

关于python - 如何在 docker-py 中绑定(bind)卷?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23286481/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com