How to use docker-py (official docker client) to run a bash shell?

I am trying to use docker-py to start a docker container and put me in a bash shell in that container. I get to start the container (I can see it using docker ps , and I can attach it very well with my own docker ps client), but when I use attach() from the official Python library, it just gives me an empty string in response . How to connect to my 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) '' 
+7
python docker dockerpy
source share
1 answer

I finished the library release for this: 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() 
+7
source share

All Articles