我认为这在几个月前就可以解决了。常规命令行泊坞窗:
>> 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
Run Code Online (Sandbox Code Playgroud)
可以正常工作,但是我无法在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']))
Run Code Online (Sandbox Code Playgroud)
..总是告诉我,新的不存在。volumes-from应该如何使用docker-py完成?
有没有一种方法可以访问私有Docker注册表的推拉访问控制?
我有一台运行私有Docker注册表的机器
sudo yum install python-devel libevent-devel python-pip gcc xz-devel
sudo python-pip install docker-registry[bugsnag]
gunicorn --access-logfile - --debug -k gevent -b 0.0.0.0:5000 -w 1 docker_registry.wsgi:application
Run Code Online (Sandbox Code Playgroud)
我从GitHub的采取这一泊坞窗注册表下运行注册表部分。
这可以正常工作,但是任何人都可以拉并推动它。我想限制谁可以拉/推到注册表的控制。
有办法吗?
感谢您的回应。
我在使用Python中的docker-py从客户端访问docker守护程序时遇到问题.我通过命令启动了一个docker守护进程,
sudo docker -d &输出结果是[1] 4894.然后我尝试使用我从这里以root身份 获得的代码从python访问守护进程
from docker import Client
cli = Client(base_url='unix://var/run/docker.sock')
cli.containers()
Run Code Online (Sandbox Code Playgroud)
这给了我错误:
requests.exceptions.ConnectionError: ('Connection aborted.', error(111, 'Connection refused'))
Run Code Online (Sandbox Code Playgroud)
我也试过了
cli = Client(base_url='tcp://127.0.0.1:4894')
Run Code Online (Sandbox Code Playgroud)
但它给了我同样的错误.
我正在尝试使用Ansible playbooks在AWS上配置我的基础架构.我有实例,并且能够提供docker-engine,docker-py等等,我发誓,昨天这个工作正常,我没有更改代码.
我的剧本的相关部分是:
- name: Ensure AWS CLI is available
pip:
name: awscli
state: present
when: aws_deploy
- block:
- name: Add .boto file with AWS credentials.
copy:
content: "{{ boto_file }}"
dest: ~/.boto
when: aws_deploy
- name: Log in to docker registry.
shell: "$(aws ecr get-login --region us-east-1)"
when: aws_deploy
- name: Remove .boto file with AWS credentials.
file:
path: ~/.boto
state: absent
when: aws_deploy
- name: Create docker network
docker_network:
name: my-net
- name: Start Container
docker_container:
name: …Run Code Online (Sandbox Code Playgroud) 我尝试运行我的test_container_services.py套件,但遇到了这个问题:
docker.errors.APIError:500服务器错误:内部服务器错误("b'{"message":"无法分配网关(10.49.0.201):地址已在使用"}'")
我试图删除所有正在运行的容器和相关网络,但仍然遇到了问题.
核心
$ uname
Linux x1 4.8.0-36-generic #36~16.04.1-Ubuntu SMP Sun Feb 5 09:39:57 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
Run Code Online (Sandbox Code Playgroud)
搬运工人
$ docker --version
Docker version 1.13.1, build 092cba3
Run Code Online (Sandbox Code Playgroud)
SDK
docker-py==1.10.6
Run Code Online (Sandbox Code Playgroud)
在运行测试之前,我处于这种状态:
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
a4beb5d4de56 bridge bridge local
8a1012b67f1a host host local
ed2452ee5e44 none null local
Run Code Online (Sandbox Code Playgroud)
没有集装箱运行$ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
def test_get_network_config(self):
number_networks = len(self.docker_api.networks())
network_config = container_services.get_network_config(
data={ …Run Code Online (Sandbox Code Playgroud) 我知道,有一种方法可以使用在主机和docker容器之间双向复制文件docker cp,也可以使用docker-py从运行的容器中获取文件。但是我无法弄清楚如何(或什至有可能)使用docker-py将文件从主机复制到正在运行的容器。你们有处理此类问题的经验吗?是否可以做,或者我必须使用python执行命令os.system。我想避免这种解决方案。
Assuming I have gotten the ecr credentials from boto already in an object called creds, when I do:
client = from_env()
client.login(creds.username, password=creds.password, registry=creds.endpoint)
Run Code Online (Sandbox Code Playgroud)
I get:
{u'IdentityToken': u'', u'Status': u'Login Succeeded'}
Run Code Online (Sandbox Code Playgroud)
Great so far! And I inspect:
client.api.__dict__
Run Code Online (Sandbox Code Playgroud)
I get:
{'_auth_configs': {'auths': {'registry_i_just_logged_into': {'email': None,
'password': 'xxxxxxxxxxxxx',
'serveraddress': 'registry_i_just_logged_into',
'username': 'xxxxxxx'},
u'some_other_registry': {},
'credsStore': u'osxkeychain'}
.... (etc, etc)
Run Code Online (Sandbox Code Playgroud)
Still so far, so good. But when I then do:
client.images.pull("registry_i_just_logged_into/some_repo", tag="latest")
Run Code Online (Sandbox Code Playgroud)
Or when I do (from a command line):
docker pull …Run Code Online (Sandbox Code Playgroud) 在命令行上,您可以运行docker tag [from] [to]为图像指定另一个名称。该文档没有提供有关如何以编程方式执行此操作的任何信息。
如何使用 docker-py 进行 docker tag 操作?
docker-py 有没有办法在分离容器之前等待运行状况检查成功?我正在尝试执行以下操作,但问题是 .run() 在运行状况检查成功之前返回。如果我尝试在 run() 之后卷曲 elasticsearch 端点,则调用失败。
cls.es = client.containers.run("elasticsearch:7.5.0", auto_remove=True,
detach=True, publish_all_ports=True,
healthcheck='curl localhost:9200/_cat/health',
ports={'9200/tcp': 9200},
environment={'discovery.type': 'single-node'})
Run Code Online (Sandbox Code Playgroud) 使用dockerPython 模块,您可以像这样启动一个分离的容器:
import docker
client = docker.from_env()
container = client.containers.run(some_image, detach=True)
Run Code Online (Sandbox Code Playgroud)
我需要等待这个容器running(即container.status == 'running')。如果您在创建容器后立即检查状态,它将报告此情况,这意味着它尚未准备好:
>>> container.status
"created"
Run Code Online (Sandbox Code Playgroud)
API 确实提供了一种wait()方法,但这仅等待终止状态,例如exit和removed: https: //docker-py.readthedocs.io/en/stable/containers.html#docker.models.containers.Container.wait。
如何等到我的容器running用于dockerPython?