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.

  • Xvfb command in docker supervisor conf not working
  • How to get exact date for docker images?
  • Docker cluster on multiple host
  • Paperclip on docker doesn't upload image?
  • Docker image NGINX not exposing : site cannot be reached
  • Use github private repo deploy key inside build stage in docker for npm install
  • 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],

  • How do use external_links to connect docker-compose to common service?
  • Docker & nginx operation not permitted
  • Shell into swarm container
  • Element not found after new sessions is created
  • How do I mount a volume in a docker container in .gitlab-ci.yml?
  • How do I wait for a pull?
  • 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.