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.

  • curl syntax error: append couchdb document failed with “conflict”?
  • FROM Command in Docker File
  • How to assign a host port to container port using docker if container is already created and running?
  • Starting Mesos slave in Docker on Amazon Linux results in cgroup error
  • Should I include my webapp source in my docker image, or mount it when i run a container?
  • How to find css/js files on a server for specified application that uses docker
  • 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],

  • Docker error while PULL - Error downloading dependent layers
  • Remove /bin/busybox at build time
  • Docker: cannot access the folder structure of based image
  • How to alter the mount point of PostgreSQL through Docker?
  • Docker and connections between containers
  • SpringBoot with Tomcat uses around 190mb of memory. What processes are running within Springboot?
  • 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.