I'm running a command line app from a Node.js process using spawn(). The process is launched with extra pipes in the stdio option. Here's a simplified code sample:
const stdio = ['ignore', 'pipe', 'pipe', 'pipe', 'pipe'];
const process = spawn('/path/to/command', [], { stdio });
// Later...
const { 3: pipeWrite, 4: pipeRead } = process.stdio;
pipeRead.on('data', (data) => {
if (String(data) === "PING?") {
pipeWrite.write("PONG!");
}
});
Now, this works fine but I want to run the command inside a docker container, using docker run as the spawned executable:
const stdio = ['ignore', 'pipe', 'pipe', 'pipe', 'pipe'];
const process = spawn(
'/usr/bin/env', [
'docker',
'run',
'--rm',
'my-image',
'/path/to/command'
], { stdio }
);
This fails, the command line app inside the docker container says it cannot write to pipe. Is it possible to achieve this with docker run?
I've set up a Github repo that demonstrates the problem, though I should make it clear that this is merely a demonstration and I do not have the means to change behaviour of the real child process (which is Chromium, in case anyone is interested!).