d11wtq / dockerpty

Pseudo-tty handler for docker Python client
https://github.com/d11wtq/dockerpty
Apache License 2.0
156 stars 62 forks source link

Dockerpty not compatible with docker version 3.0.0 #79

Open falu2010 opened 6 years ago

falu2010 commented 6 years ago

Looks like dockerpty is not compatible with docker version 3.0.0.

vanpelt commented 5 years ago

It actually works with 3.0.0, you just need to pass in the low level api to start.

image = "nginx"
dir = "/app"
cwd = os.getcwd()
container = client.api.create_container(
        image,
        "/bin/sh",
        volumes=[dir],
        host_config=client.api.create_host_config(
            binds={cwd: {"bind": dir, 'mode': 'rw'}}
        ),
        stdin_open=True,
        tty=True,
        environment={
            "LANG": "C.UTF-8"
        }
    )
    dockerpty.start(client.api, container)
lacek commented 5 years ago

It also works with client.containers.create with a simple replacement of container by container.id in the call of start:

client = docker.from_env()
container = client.containers.create(...)
dockerpty.start(client.api, container.id)