cli icon indicating copy to clipboard operation
cli copied to clipboard

Feature request: allow attaching (`docker run -a`) to additional file descriptors

Open andyearnshaw opened this issue 2 years ago • 0 comments

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 });

// I can access the streams for fd3 and fd4 through the child process's `stdio` object
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. There doesn't appear to be any way to attach to these extra streams when using docker run.

andyearnshaw avatar Jun 15 '22 17:06 andyearnshaw