Extraneous output in Docker API responses when using Unix domain socket?

I’m writing an app that communicates with the Unix domain socket (/var/run/docker.sock) to control the Docker daemon.

On some requests, I’ve noticed there seems to be extraneous output being injected into the response. Here is a sample of the output (each [in] line is a separate line of output):

Connecting to the socket.
Connected.
Request sent.
[in] HTTP/1.1 200 OK
[in] Api-Version: 1.39
[in] Content-Type: application/json
[in] Docker-Experimental: false
[in] Ostype: linux
[in] Server: Docker/18.09.7-ce (linux)
[in] Date: Mon, 15 Jul 2019 18:21:53 GMT
[in] Connection: close
[in] Transfer-Encoding: chunked
[in]
[in] cff
[in] [{"Id":"aee24535de51249f48ba53116f0f5e4ca6b1fb3e39b39cc90b182aaa4ade06c6"...
[in]
[in] 0
[in]

The lines containing “cff” and a “0” are extra. They seem to show up anytime I make the request for containers/json. The “cff” also changes, it appears to be an incrementing hex counter (it was cfc earlier, a later run returned d02).

The API docs make no obvious mention of this extra data (at least in the documentation for the “Get Containers” endpoint at /containers/json")

I can filter out the extra data obviously, but I’m curious as to why it is there and what its purpose is.

    docker3:~# docker info
Containers: 3
 Running: 3
 Paused: 0
 Stopped: 0
Images: 7
Server Version: 18.09.7-ce
Storage Driver: zfs
 Zpool: error while getting pool information strconv.ParseUint: parsing "": invalid syntax
 Zpool Health: not available
 Parent Dataset: pool0/docker
 Space Used By Parent: 2043408384
 Space Available: 70557466624
 Parent Quota: no
 Compression: lz4
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 85f6aa58b8a3170aec9824568f7a31832878b603
runc version: 425e105d5a03fabd737a126ad93d62a9eeede87f
init version: v0.18.0 (expected: fec3683b971d9c3ef73f284f176672c44b448662)
Kernel Version: 4.19.53-0-vanilla
Operating System: Alpine Linux v3.10
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 3.822GiB
Name: docker3
ID: ***
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

What you see are the markers of the chunks. This has to do with “Transfer-Encoding: chunked”. It’s part of the specification: Chunked transfer encoding - Wikipedia

The Docker API does not seem to respect the request header “Accept-Encoding”. No matter what you request, you always get chunked responses.

Haha, thanks for the reply. I think I figured that out a while ago, when I was working on an unrelated project making direct HTTP calls via sockets to an IoT device that used HTTP chunking. The original app I was writing for Docker was in .NET, but I’m now doing a lot more Python work and am porting that work over to Python, and there appears to be a way to use Requests (or a fork of it) to make HTTP calls to Unix sockets.