Docker API : Show container logs in a webpage

I’m working on a project for a docker web client in node.js using the package from Appersonlabs In order to build a complete client, I want to stream the container logs to a webpage. Here’s my route using the api :

    console.log('INSPECT CONTAINER WITH ID ';
      docker.containers.attach(, {stream: true, stdout: true, stderr:false, tty:false}, function(err,stream) {
        res.render('containers/show.ejs',{container: infos, name: name, stream: stream});

But when I console.log the stream I got a big JSON files with a bunch of output information.

  • docker container interface not being attached to docker0 bridge in coreos
  • Propgate changes from base image to “child” image, Docker
  • Using two docker files - dev and prod
  • How to build a docker container for a synchronized source code?
  • Play Framework app in Docker is not working
  • Specify environment on start of component
  • According to docker’s API here’s how I should proceed (


    The simplest way to implement the Attach protocol is the following:

    Read 8 bytes

    • chose stdout or stderr depending on the first byte
    • Extract the frame size from the last 4 bytes
    • Read the extracted size and output it on the correct output
    • Goto first step

    Question :

    How should I proceed to achieve that ? I really don’t know how to start.

    NOTE : As far as I know my http request is correct, here’s a sample of the JSON response I get from the API:

    method: 'POST',
        path: 'http://localhost:4243/v1.7/containers/8196569ecaaf2bbcf726189b60212676ad1351f6ff4df6ebe9deb4743b52e138/attach?stream=true&stdout=true&stderr=false&tty=false',
        _headers: [Object],

  • Best way to to implement Spark + AWS + Caffe/CUDA?
  • Vagrant with Docker Provider requires RSync Password
  • How to check whether a docker service is already running on UCP using shell script
  • How to change resolv.conf for existing docker containers
  • docker swarm port publishing not mapping
  • Why doesn't my newly-created docker have a digest?
  • 2 Solutions collect form web for “Docker API : Show container logs in a webpage”

    I think you need to add “logs: true” in attach options :

    docker.containers.attach(containerId, {logs: true, stream: true, stdout: true, stderr: false, tty: false}, function(err, stream)

    I just tested it, it works fine on docker 0.9.1.

    If you find this post as I did and would like to get a basic, working example for the implementation:

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.