Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exec in interactive mode #57

Open
JulienB37 opened this issue Dec 18, 2018 · 3 comments
Open

exec in interactive mode #57

JulienB37 opened this issue Dec 18, 2018 · 3 comments
Labels

Comments

@JulienB37
Copy link

Hi,

How can i make an exec command with the interactive mode ??
I'm looking for a way to do docker exec -it test /bin/bash with docker api.

Thanks for helping.

@sabrehagen
Copy link
Contributor

Hi @JulienB37, did you get this working? If so, can you post your code please? Did you stream input to the container's stdin?

@JulienB37
Copy link
Author

hi,
i did not find a good solution :(

And finally i use docker with chid_process to execute a docker command in interactive mode

const {execFileSync} = require('child_process')
execFileSync('docker', ['exec', '-it', 'myContainer', '/bin/bash'], {stdio: 'inherit'});

If someone has a better solution it would be nice

@sabrehagen
Copy link
Contributor

I ended up with a hacky solution by accessing the .connection property of the stream returned from exec.start() as seen in the last line below. I assume this is not the intended approach.

  import { tarStream } from 'tar-stream';

  // The outgoing tar compression stream
  const tarCompressor = tarStream();

  const syncContainer = await docker.container.create({
    Binds: volumesToSync,
    Cmd: ['sleep', 'infinity'],
    Image: 'stemn/development-environment:latest',
  });

  await syncContainer.start();

  // Create a tar extractor pointng at the root of the filesystem
  const tarExtractorExec = await syncContainer.exec.create({
    AttachStdin: true,
    Cmd: ['tar', 'xf', '-'],
    OpenStdin: true,
    WorkingDir: '/',
  });

  // The receiving tar extractor stdio stream
  const tarExtractor = await tarExtractorExec.start();

  // Pipe the tar compression stream to the standard input of the tar extractor
  tarCompressor.pipe(tarExtractor.connection);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants