-
- Notifications
You must be signed in to change notification settings - Fork 482
Closed
testcontainers/testcontainers-node
#489Labels
Description
I want to execute a command in an already running container using "exec". For some reason, the stream returned by "exec.start()" is not emitting the "end" event. So, I have no way of knowing when the command completes and the Node process doesn't end.
Example code is below. Am I doing something wrong, or is this a bug?
const Docker = require("dockerode"); const docker = new Docker(); const PassThrough = require("stream").PassThrough; (async () => { try { // Create/start container, if necessary. let container = docker.getContainer("test"); let info; try { info = await container.inspect(); } catch (error) { if (error.statusCode !== 404) throw error; container = await docker.createContainer({ Image: "ubuntu", Tty: true, name: "test" }); } info = await container.inspect(); if (info.State.Running !== true) await container.start(); // Execute 'cat' with data piped to stdin. const exec = await container.exec({ AttachStdin: true, AttachStdout: true, AttachStderr: true, Tty: false, Cmd: ["cat"] }); const stream = await exec.start({ hijack: true, stdin: true }); const input = new PassThrough(); input.write("test one\ntest two\n"); input.pipe(stream.output); docker.modem.demuxStream(stream.output, process.stdout, process.stderr); stream.output.on("end", async () => { // Event is not emitted. console.log(await exec.inspect()); }); } catch (error) { console.error(error); } })();jankoritak, davidreis97, Edoldin, onurtemizkan, pimterry and 5 more