Tag: dockerpy

如何用docker-py绑定端口

我尝试使用docker-py(版本1.3.1)启动docker容器。 我想映射容器的内部端口到不同的端口,但没有正确的公开。 我这样做是这样的: def start_container(client, host_config, image_tagged_name, command): print ("create_host_config", host_config.binds, host_config.port_bindings) the_host_config = create_host_config(binds = host_config.binds, port_bindings = host_config.port_bindings); the_ports = host_config.port_bindings.values(); print ("create_container", image_tagged_name, command, the_ports, the_host_config) cont_id = client.create_container(image=image_tagged_name, command=command, ports=the_ports, host_config=the_host_config)["Id"] 在这种情况下,产出如下: create_host_config ['/dbfiles/test:/opt/db'] {3001: 3000, 2425: 2424, 2481: 2480} create_container test:test ./initdb.sh [3000, 2424, 2480] {'Binds': ['/dbfiles/test:/opt/db'], 'PortBindings': {'3001/tcp': [{'HostPort': […]

Python docker-py拒绝连接

我在使用Python中的docker-py从客户端访问docker守护进程时遇到了麻烦。 我用sudo docker -d &命令启动了一个docker守护进程,输出是[1] 4894 。 然后我尝试从python使用我从这里得到的代码作为root访问守护进程 from docker import Client cli = Client(base_url='unix://var/run/docker.sock') cli.containers() 这给了我错误: requests.exceptions.ConnectionError: ('Connection aborted.', error(111, 'Connection refused')) 我也试过了 cli = Client(base_url='tcp://127.0.0.1:4894') 但它给了我同样的错误。

如何绑定docker-py中的卷?

我觉得这个习惯在几个月前就已经完成了。 常规的命令行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 […]

pipe道数据exec_create&标准input/标准输出

我已经重写了这个问题,以更好地沟通我想要实现的目标。 如果我使用docker CL,这对我来说是完美的。 echo "hello" | docker exec -i $3 sh -c 'cat >/text.txt' 现在我想使用docker-py,并有这个到目前为止: ex = cli.exec_create(container='nginx-ssl', cmd='cat >/text.txt') print cli.exec_inspect(ex) ls = cli.exec_start(exec_id=ex["Id"], tty=True) 那么如何将“hello”或任何数据传递给exec命令,以便复制CL命令? 顺便说一句,这也适用于本地: p = Popen(('docker', 'exec', '-i', 'nginx-ssl', 'sh', '-c', 'cat >text.txt'), stdin=subprocess.PIPE) p.communicate('hello\n') p.stdin.close()

Dockerpy执行命令到猫日志文件

这看起来很简单,但我想用Docker-py复制下面的Docker命令: docker exec dockerName cat /var/log/foo.log 使用dockerpy,似乎下面应该工作: from docker.client import Client from docker.utils import kwargs_from_env cli = Client(**kwargs_from_env()) print kwargs_from_env() name_one = 'exec_container' cli.create_container(**{'name': name_one, 'image': 'golang'}) cli.start(name_one) cli.logs(name_one, stdout=True, stderr=True) # commenting this line out allows the below to execute perfectly e = cli.exec_create(container=name_one, cmd='ls /usr/local/bin') print cli.exec_start(exec_id=e['Id']) 但是,当我运行此我收到以下错误跟踪: File "/Library/Python/2.7/site-packages/docker/utils/decorators.py", line 35, in […]

Docker容器在docker-py库中等待/运行时间

我使用docker-py(create_container函数)来创build多个Docker容器,我的代码工作正常,并为我创build容器,一段时间后容器自动退出,但是我想在这里实现的事情是,我希望所有的容器处于运行模式所需的时间,例如我希望所有的容器处于运行模式5分钟或10分钟等等等等。我已经在命令参数中添加了“睡眠”,但它不适用于我,请帮忙 ! 我没有太多经验的python..我执行的function是; for i in range(0,5): container = client.create_container( image='syed/syedclients:helloworld', stdin_open=True, tty=True, command='/bin/bash saad.sh /bin/sleep 180', name=hello-1, volumes=volumes, host_config=host_config, environment=['VARIABLE=xyz123'], detach=True, ) client.start(container)

docker-py:如何将IP地址绑定到容器

说我有一个名为“mynet”的networking,我想启动一个IP地址绑定到192.168.23.2的容器。 我开始的代码是: import docker c = docker.from_env() c.containers.run('containername', 'sh some_script.sh', network='mynet') 我从这里做什么? 我正在有效地寻找相当于docker run的–ip选项。

如何使用docker-py(官方docker客户端)启动bash shell?

我正在尝试使用docker-py来运行一个docker容器并将其放入该容器中的bash shell中。 我得到尽可能运行容器(我可以看到它用docker ps ,我可以附加到它本地docker客户端很好),但是当我从正式的Python库使用attach() ,它只是给了我一个空string作为响应。 我如何附加到我的bash shell? >>> import docker >>> c = docker.Client() >>> container = c.create_container(image='d11wtq/python:2.7.7', command='/bin/bash', stdin_open=True, tty=True, name='docker-test') >>> container {u'Id': u'dd87e4ec75496d8369e0e526f343492f7903a0a45042d312b37859a81e575303', u'Warnings': None} >>> c.start(container) >>> c.attach(container) ''

Ansible docker_container'否请求URL中的主机',docker pull正常工作

我正在尝试使用Ansible操作手册在AWS上configuration我的基础架构。 我有这个实例,并且能够configurationdocker-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 […]

如何在docker-py中运行基本的Web应用程序容器?

我试图模仿运行一个集装箱化的Web应用程序暴露在一些端口 sudo docker run -d -p 1338:1337 kermit/hellonode 在Python中使用docker-py 。 到目前为止,我得到了这个代码来启动实例: container = c.create_container('kermit/hellonode', name='hello') c.start(container, port_bindings={1337: ('0.0.0.0', 1338)}) 但我不能访问在公共端口1338容器(这与第一个命令正常工作) – 我得到连接拒绝错误。 有谁知道如果我错过了一些选项,使Python调用创buildfunction,可访问的容器? 检查集装箱告诉我,港口设置应该是这样的: $ sudo docker port hello 1337 0.0.0.0:1338 我也尝试了create_container调用中的ports=[1337]选项,但是也没有帮助。 更新:似乎这是某种错误 。 解决方法是明确指定TCP: container = c.create_container('kermit/hellonode', name='hello', ports=[(1337, 'tcp')])