docker-py icon indicating copy to clipboard operation
docker-py copied to clipboard

How to interact with docker and return information, similar to docker exec -it ubuntu /bin/bash

Open DaDong-G opened this issue 3 years ago • 0 comments

import docker

client = docker.DockerClient("tcp://192.168.186.144:2375") socket = client.containers.get("cb07b0ec35c2").exec_run("/bin/bash", stdin=True, socket=True) socket._sock.sendall(b"ls / -la\n") data= socket._sock.recv(1024) print(data) try: unknown_byte = socket._sock.recv(1024) print(unknown_byte) while True: part = socket._sock.recv(1024) data += part if len(part) < buffer_size: break except Exception: pass socket._sock.send(b"exit\n")

It will get stuck after execution。

DaDong-G avatar Jun 23 '22 09:06 DaDong-G