Docker run command + returning output

Ok, this question is a bit open ended so I can’t post it on StackExchange without getting down voted. I’m hoping the good folks of this forum will be able to help point me in the right direction…

Without going too in depth, my app has users executing code, unit testing it and then displaying whether it passed or failed the unit test(s). It’s similar to code wars.

To securely achieve this, I must execute a docker run command which creates a new container and removes the container when finished. On the command line, I have this working perfectly with the help of some open source code, but I have no idea how to send the code to the CLI and return its output (within my app).

I’m new to meteor and programming in general to be honest, but I’m determined to see this project through. All I want to know is what direction I should be looking in terms of learning how to accomplish this.

This might be what you’re looking for

1 Like

Thank you. This is indeed what I was looking for.

I hope someone can help me figure out why dockerode is giving me an error.

In server/test.js:

import Docker from 'dockerode';

Meteor.methods({
  testMethod:function(){

    var docker = new Docker({socketPath: '/var/run/docker.sock'});
    docker.createContainer({Image: 'ubuntu', Cmd: ['/bin/bash'], name: 'ubuntu-test'}, function (err, container) {
      container.start(function (err, data) {
        if (err) {
          console.log(err);
        }
        else {
          console.log(data);
        }
      });
    });

  }
});

After deploying to a digital ocean droplet using mupx, I call the method and get the following error when viewing the logs from the container my app is installed in:

TypeError: Cannot call method 'start' of null
    at server/test.js:8:17
    at /bundle/bundle/programs/server/npm/node_modules/dockerode/lib/docker.js:37:21
    at [object Object].Modem.buildPayload (/bundle/bundle/programs/server/npm/node_modules/docker-modem/lib/modem.js:225:19)
    at ClientRequest.<anonymous> (/bundle/bundle/programs/server/npm/node_modules/docker-modem/lib/modem.js:210:10)
    at ClientRequest.emit (events.js:95:17)
    at Socket.socketErrorListener (http.js:1603:9)
    at Socket.emit (events.js:95:17)
    at net.js:441:14
    at process._tickCallback (node.js:458:13)

Any advice would be greatly appreciated.