use socket from exec_run in python3 (python2 is working) -- 'SocketIO' object has no attribute 'sendall'
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 1.7k
- Avg merge
- 13d 8h
- Merged PRs (30d)
- 2
Description
The following code works fine with pyhton2 (docker-py 2.5.1), but not with python3 (docker-py 3.7.0)
import docker
client = docker.DockerClient(base_url='unix://var/run/docker.sock', version='auto')
container = client.containers.run("gliderlabs/alpine", command= "sleep 100", detach = True)
socket = container.exec_run(cmd="sh", stdin=True, socket = True)
socket.sendall(b"ls\n")
# a read block after a send
try:
unknown_byte=socket.recv(1)
while 1:
# note that os.read does not work
# because it does not TLS-decrypt
# but returns the low-level encrypted data
# one must use "socket.recv" instead
data = socket.recv(16384)
if not data: break
print(data.decode('utf8'))
except so.timeout: pass
socket.sendall(b"exit\n")
in python3 "container.exec_run" returns ExecResult(exit_code=None, output=<socket.SocketIO object at 0x7f5bb7f7c160>).
So my idea was to use socket.output.sendall(b "ls\n"), but then I always get the error AttributeError: 'SocketIO' object has no attribute 'sendall'"".
The documentation says only If socket=True, a socket object for the connection, and sendall() is a socket method for me.
How to use exec_run in python3?
Source:
https://github.com/docker/docker-py/issues/983
https://stackoverflow.com/questions/46521166/how-to-write-to-stdin-in-a-tls-enabled-docker-using-the-python-docker-api
https://github.com/mailcow/mailcow-dockerized/pull/2297
Version:
docker-host:
{'Platform': {'Name': ''}, 'Components': [{'Name': 'Engine', 'Version': '18.03.1-ce', 'Details': {'ApiVersion': '1.37', 'Arch': 'amd64', 'BuildTime': '2018-04-26T07:15:30.000000000+00:00', 'Experimental': 'false', 'GitCommit': '9ee9f40', 'GoVersion': 'go1.9.5', 'KernelVersion': '4.15.0-45-generic', 'MinAPIVersion': '1.12', 'Os': 'linux'}}], 'Version': '18.03.1-ce', 'ApiVersion': '1.37', 'MinAPIVersion': '1.12', 'GitCommit': '9ee9f40', 'GoVersion': 'go1.9.5', 'Os': 'linux', 'Arch': 'amd64', 'KernelVersion': '4.15.0-45-generic', 'BuildTime': '2018-04-26T07:15:30.000000000+00:00'}
conatiner
Alpine 3.9 with docker-py 3.7.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the container.exec_run entry point and reproduce the Python 3 case with socket=True using the example in the issue. Trace the returned ExecResult output and socket handling, then verify that interactive stdin supports the documented send and receive workflow without the SocketIO AttributeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100