[英]How to use docker-py (official docker client) to start a bash shell?
I'm trying to use docker-py to run a docker container and drop me into a bash shell in that container. 我正在尝试使用docker-py运行一个docker容器并将我放入该容器中的bash shell中。 I get as far as running the container (I can see it with
docker ps
, and I can attach to it just fine with the native docker client), but when I use attach()
from the official Python library, it just gives me an empty string in response. 我得到了运行容器(我可以使用
docker ps
看到它,我可以使用本机docker客户端很好地附加它),但是当我使用官方Python库中的attach()
,它只是给了我一个空字符串作为回应。 How do I attach to my bash shell? 如何附加到我的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)
''
I ended up releasing a library for this: https://github.com/d11wtq/dockerpty 我最终为此发布了一个库: https : //github.com/d11wtq/dockerpty
import docker
import dockerpty
client = docker.Client()
container = client.create_container(
image='busybox:latest',
stdin_open=True,
tty=True,
command='/bin/sh',
)
client.start(container)
dockerpty.PseudoTerminal(client, container).start()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.