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

put_archive: note the data may also be a stream

Open akx opened this issue 6 years ago • 4 comments

The docs imply the data parameter to put_archive() must be bytes (a bytestring), which is not the case; a stream is fine too since it's passed directly to Requests.

In fact, the tests for the put_archive() feature always pass in a stream:

https://github.com/docker/docker-py/blob/a0b9c3d0b38abd4af1880ca3dde2845556dd2f70/tests/integration/api_container_test.py#L678-L679

akx avatar Dec 10 '19 10:12 akx

This is also something I noticed recently. I've taken a look at the Requests adapters provided by docker-py, it doesn't look like they do anything funky which will prevent this. But I'm not really familiar with these aspects of Requests (and the adapters) to be able to say this with full confidence :)

felixfontein avatar Jan 25 '20 16:01 felixfontein

@felixfontein Well, it works for me in production as we speak 😁

akx avatar Jan 27 '20 12:01 akx

@akx out of curiosity, which transports are you using it with / did you test it with? There's unix, tcp, tcp+tls, ssh+unix, and npipe (Windows only).

felixfontein avatar Jan 28 '20 05:01 felixfontein

@felixfontein Plain UNIX in this instance.

akx avatar Jan 28 '20 06:01 akx

Hi, After a code review of request.py and Go docker client, I can confirm:

  • request accepts streams (documentation: file-like objects) as data field. iter and read methods are expected.
  • docker cp command with stdin as input uses such a mechanism. By the way, tar archive may be a tar gzipped archive. Sucessfully tested with 4 Go of compressed tar archive.

damwiw avatar Jan 12 '23 08:01 damwiw

Rebased. Could a maintainer take a look?

akx avatar Feb 03 '23 17:02 akx