dockerode icon indicating copy to clipboard operation
dockerode copied to clipboard

How I can get process ID (PID) of a executed command?

Open carromeu opened this issue 11 months ago • 0 comments

I am using Dockerode to create a Web Terminal. That works fine. However, when user close console, I need to kill de ash, bash, dash or sh process attached to Xterm. To this, I need to store the PID in the moment of exec command:

const exec = await container.exec({
  Cmd: [ '/bin/' + command ],
  AttachStdin: true,
  AttachStdout: true,
  User: 'root',
  Tty: true,
})

const stream = await exec.start({ stdin: true, hijack: true, Detach: false });

I try the inspect command (const data = await exec.inspect()), but the PID returned is not of process.

Is there a way to get this PID by Dockerode?

carromeu avatar Mar 08 '25 13:03 carromeu