docker api, attaching container returns extra characters

I’m consuming docker api from javascript in the browser,
I start one container that executes ‘composer install’ command then I attach to it to get the output.
Everything works but I get some extra characters at the beginning of each line

    -Installing assets using the hard copy option
    PInstalling assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework
    BInstalling assets for Propel\PropelBundle into web/bundles/propel

P and B before installing word in this two line example in particular, but in reality are random letters or numbers.

  • Upload a container to registry V2 using API (2.5.1)
  • curl: (7) Failed to connect to port 80: Connection refused
  • libcurl with ares on ubuntu 14.04
  • AWS ECS weird docker behavior
  • PHP echo statement with URL parameter
  • Consul is unable to find the cluster leader
  • do I need to parse or process the output of attached container before displaying it ?

    Note: Not only from browser but from terminal curl command too, also getting same random characters at beginning of almost line

    curl 'http://localhost/dockerapi/containers/54053a10dc05b45c400b16733d2edd1cbfb6b6d877badf5cc26d3da7d2165375/attach?logs=1&stream=1&stdout=1' 
    -X POST 
    -H 'Origin: http://localhost' 
    -H 'Accept-Encoding: gzip,deflate,sdch' 
    -H 'Accept-Language: en-US,en;q=0.8,es;q=0.6' 
    -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36'
    -H 'Accept: application/json, text/plain, */*' 
    -H 'Referer: http://localhost/' 
    -H 'Connection: keep-alive'
    -H 'Content-Length: 0' 

  • Kibana can't reach elasticsearch
  • How does Istio compare to Traefik?
  • Accessing docker container mysql databases
  • could not read Username for '': No such device or address
  • Is it possible to mount a directory while building from Dockerfile?
  • Logstash Configuration file in Docker ELK Compose file
  • One Solution collect form web for “docker api, attaching container returns extra characters”

    Turns out that this is documented here

    I just overlooked because the text format I thought was the rest of the response but it was in fact documentation.
    It’s been clarified by @soullou user in

    It is encoded on the first 8 bytes like this:
    header := [8]byte{STREAM_TYPE, 0, 0, 0, SIZE1, SIZE2, SIZE3, SIZE4}
    `STREAM_TYPE` can be:
    -   0: stdin (will be written on stdout)
    -   1: stdout
    -   2: stderr
    `SIZE1, SIZE2, SIZE3, SIZE4` are the 4 bytes of
    the uint32 size encoded as big endian.
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.