Dockerode: "docker exec -it <container-name> -u root -p" on dockerode

Created on 17 Jun 2019  路  3Comments  路  Source: apocas/dockerode

Hi all,

I have a small issue on creating the following docker execution

docker exec -it mysql1 mysql -uroot -p

I have interpreted this in dockeorde as follows,

function runExec(container) {
  let options = {
    Cmd: ["mysql"],    
    AttachStdin: true,
    AttachStdout: true,
    AttachStderr: true,
    Tty: true,
    OpenStdin: true,
    StdinOnce: false,
  };

  container.exec(options, function(err, exec) {
    if (err) {
      console.log(err);
      return;
    }
    exec.start(
      {stdin: true, 
       hijack: true},
      function(err, stream) {

      if (err) {
        console.log(err);
        return;
      }
        container.modem.demuxStream(stream, process.stdout, process.stderr);
      }
    });
  });
}

But this doesn't help me to enter the password and get inside the container, btw I'm trying to execute MYSQL-server docker image through dockerode. Any help would be appreciated.

question

All 3 comments

Have you checked this example:
https://github.com/apocas/dockerode/blob/master/examples/run_stdin.js

It should send you in the right direction :)

@lakindu95 customize this may help you

  public async interactiveShell(containerName: string) {
    const container = this.dockerApi.getContainer(
      containerName
    );

    const exec = await container.exec({
      Cmd: ['sh'],
      AttachStderr: true,
      AttachStdout: true,
      AttachStdin: true,
      Tty: true,
    });

    const http = await exec.start({stdin: true});
    const stream = http.output;

    (<any>process.stdin).setRawMode(true);
    stream.pipe(process.stdout);
    process.stdin.pipe(stream);
    stream.write('ls/n'); // ls inside interactive shell


    await new Promise(resolve => {
      stream.on('end', resolve);
    });

    (<any>process.stdin).setRawMode(false);
    process.stdin.resume();

  }

Thanks for the responses, I have used the example which @apocas provided. This is how I overcome the issue in my repo.

https://github.com/lakindu95/clocal-azure/blob/master/src/services/azure-sql-server/azure-sql-server.js

Was this page helpful?
0 / 5 - 0 ratings