Fix to enable streaming container logs reliably
Started a ubuntu container that just runs "ping 8.8.8.8" and tried the sample code in https://gist.github.com/dims/c3327f633c526847c8e5 to recreate the problem mentioned in: https://github.com/docker/docker-py/issues/300 To debug the problem i printed the byte array read in recvall when reading STREAM_HEADER_SIZE_BYTES and realized that the data being read was far ahead of the actual start of the header documented in the vnd.docker.raw-stream of the docker remote api. This is possibly because the requests/urllib3 is reading ahead a bit more and we shouldn't be trying to hack the internals of those projects. So just using the documented file-like response.raw is good enough for us to get the functionality we need which is being able to read for exactly where the stream header starts. With this change i can reliably stream the logs just like "docker logs --follow". Note that we still need to access the underlying socket to set the timeout to prevent read time outs. The original fix was for client.logs() only but on further review it made sense to replace all occurances of _multiplexed_socket_stream_helper with the new method.
Showing
Please
register
or
sign in
to comment