dockerode
dockerode copied to clipboard
exec via ssh uncaughtException
let Docker = require('dockerode');
let docker = new Docker({
protocol: 'ssh',
host: "192.111.111.111", // put any unreachable ip address
port: 22,
username: 'root',
sshOptions: {
privateKey: require('fs').readFileSync('/root/.ssh/id_rsa'),
},
});
let containerid = 'xxx';
let container = docker.getContainer(containerid);
let params = {
Cmd: ['sh', '-c', 'ls'],
AttachStdin: false,
AttachStdout: true,
AttachStderr: true,
Tty: false,
Env: [],
};
console.log('exec');
container.exec(params, (err, exec) => {
// never reached
console.log('exec done');
});
it works on dev machine, but not on the other. It is related to networking but the fact is i get an uncaughtException. Is it normal ? console.log('exec done'); is never called. how can i handle the error properly ?
the actual error :
uncaughtException Timed out while waiting for handshake {
"err": {
"level": "client-timeout",
"code": null,
"name": "Error",
"message": "Timed out while waiting for handshake",
"detail": null,
"stack": [
"Error: Timed out while waiting for handshake",
" at Timeout._onTimeout (/usr/app/node_modules/ssh2/lib/client.js:695:19)",
" at listOnTimeout (node:internal/timers:557:17)",
" at processTimers (node:internal/timers:500:7)"
],
"err": null
}
}