I am trying to run an async node child_process which runs a docker container.
let runDockerCmd = `docker-compose -f ./vm/docker-compose.yml run --rm vm node temp.js`;
child_process.exec(runDockerCmd, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
});
Where temp.js contains a for loop
. Sometimes it runs half the loop, sometimes a third etc. then it terminates.
I can get it to work using child_process.execSync
but that is a bit unsavoury. Why does it exit like that, and how do I keep it alive?