We can follow their example here
Basically, you will need to create a container, start it manually and exec
inside to run our own script.
Credit to https://github.com/apocas/dockerode/issues/106
EDIT 1: To show an example of how to apply the example to your use case:
// Instantiate Docker
var Docker = require("dockerode");
var docker = new Docker({ socketPath: "/var/run/docker.sock" });
function runExec(container) {
var options = {
Cmd: ["python", "run.py", authorization, "test_data_source", dataSourceId.toString()],
AttachStdout: true,
AttachStderr: true
};
container.exec(options, function(err, exec) {
if (err) return;
exec.start(function(err, stream) {
if (err) return;
container.modem.demuxStream(stream, process.stdout, process.stderr);
exec.inspect(function(err, data) {
if (err) return;
console.log(data);
// Your code continue here
});
});
});
}
docker.createContainer({
Image: 'mobydq-scripts',
Tty: true,
Cmd: ['/bin/bash', '-c', 'tail -f /dev/null'],
name: "mobydq-test-data-source",
HostConfig: { AutoRemove: true, NetworkMode: "mobydq_network" }
}, function(err, container) {
container.start({}, function(err, data) {
runExec(container);
});
});
You can also take a look at their README where they createContainer
and attach
to it.