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.

  • Public Docker v2 API Endpoints
  • HTTP/2 nginx force redirect HTTP to HTTPS breaks expected behaviour
  • Running elasticsearch on Azure VM using Docker: cannot access via localhost
  • Pull docker images from private registry on remote host?
  • cURL to DropBox using Symfony 3
  • Why php-fpm from official Docker image doesn't work for me?
  • 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' 

  • dockerize c#.NET desktop application
  • How can a bash script restart a process on non-0 exit while sending signals to child
  • Boot2Docker to Google Compute Engine VM: saving Docker container
  • Updating kubectl with new configurations
  • Why am I getting an RTNETLINK Operation Not Permitted when using Pipework with Docker containers?
  • Mesos Marathon Docker Containers - CommandInfo
  • 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.