Docker exec and terminal on Windows

This commit is contained in:
Jeffrey Morgan
2015-06-12 07:32:50 +01:00
parent 20cce37dc5
commit b923bc06a7
4 changed files with 18 additions and 42 deletions

View File

@@ -12,6 +12,7 @@ var classNames = require('classnames');
var resources = require('../utils/ResourcesUtil');
var dockerUtil = require('../utils/DockerUtil');
var containerActions = require('../actions/ContainerActions');
var dockerMachineUtil = require('../utils/DockerMachineUtil');
var ContainerDetailsSubheader = React.createClass({
contextTypes: {
@@ -111,26 +112,7 @@ var ContainerDetailsSubheader = React.createClass({
if(!shell) {
shell = 'sh';
}
machine.ip().then(ip => {
if(util.isWindows()) {
var cmd = ['ssh', '-p', '22', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'LogLevel=quiet', '-o', 'StrictHostKeyChecking=no', '-i', util.home() + '/.docker/machine/machines/' + machine.name() + '/id_rsa', 'docker@' + ip, '-t', 'docker',
'exec', '-i' , '-t', container.Name, shell];
console.log(cmd.join(" "));
util.execProper('start cmd.exe /C "' + cmd.join(" ") + '"', function (stderr, stdout, code) {
if (code) {
console.log(stderr);
}
});
} else {
var cmd = [resources.terminal(), 'ssh', '-p', '22', '-o', 'UserKnownHostsFile=/dev/null', '-o', 'LogLevel=quiet', '-o', 'StrictHostKeyChecking=no', '-i', '~/.docker/machine/machines/' + machine.name() + '/id_rsa', 'docker@' + ip, '-t', 'docker',
'exec', '-i', '-t', container.Name, shell];
exec(cmd, function (stderr, stdout, code) {
if (code) {
console.log(stderr);
}
});
}
});
dockerMachineUtil.dockerTerminal(`docker exec -it ${this.props.container.Name} ${shell}`);
}
},
handleItemMouseEnterView: function () {

View File

@@ -42,7 +42,7 @@ var _steps = [{
progressCallback(50); // TODO: detect when the installation has started so we can simulate progress
try {
if (util.isWindows()) {
yield util.exec([path.join(util.supportDir(), virtualBox.filename())]);
yield util.exec([path.join(util.supportDir(), virtualBox.filename()), '-msiparams', 'REBOOT=ReallySuppress', 'LIMITUI=INSTALLUILEVEL_PROGRESSONLY']);
} else {
yield util.exec(setupUtil.macSudoCmd(setupUtil.installVirtualBoxCmd()));
}
@@ -57,7 +57,7 @@ var _steps = [{
message: 'To run Docker containers on your computer, Kitematic is starting a Linux virtual machine. This may take a minute...',
totalPercent: 60,
percent: 0,
seconds: 72,
seconds: 80,
run: Promise.coroutine(function* (progressCallback) {
setupUtil.simulateProgress(this.seconds, progressCallback);
var exists = yield machine.exists();

View File

@@ -153,23 +153,29 @@ var DockerMachine = {
});
});
},
dockerTerminal: function () {
dockerTerminal: function (cmd) {
if(util.isWindows()) {
cmd = cmd || '';
this.info().then(machine => {
util.execProper('start cmd.exe /k',
{'env': {
util.exec('start powershell.exe ' + cmd,
{env: {
'DOCKER_HOST' : machine.url,
'DOCKER_CERT_PATH' : path.join(util.home(), '.docker/machine/machines/' + machine.name),
'DOCKER_TLS_VERIFY': 1
'DOCKER_TLS_VERIFY': 1,
'PATH': resources.resourceDir()
}
});
});
} else {
cmd = cmd || '$SHELL';
this.info().then(machine => {
var cmd = [resources.terminal(), `DOCKER_HOST=${machine.url} DOCKER_CERT_PATH=${path.join(util.home(), '.docker/machine/machines/' + machine.name)} DOCKER_TLS_VERIFY=1 $SHELL`];
var cmd = [resources.terminal(), `DOCKER_HOST=${machine.url} DOCKER_CERT_PATH=${path.join(util.home(), '.docker/machine/machines/' + machine.name)} DOCKER_TLS_VERIFY=1 ${cmd}`];
util.exec(cmd).then(() => {});
});
}
},
exec: function () {
}
};

View File

@@ -1,5 +1,5 @@
var exec = require('exec');
var execProper = require('child_process').exec;
var child_process = require('child_process');
var Promise = require('bluebird');
var fs = require('fs');
var path = require('path');
@@ -10,8 +10,9 @@ var app = remote.require('app');
module.exports = {
exec: function (args, options) {
options = options || {};
let fn = Array.isArray(args) ? exec : child_process.exec;
return new Promise((resolve, reject) => {
exec(args, options, (stderr, stdout, code) => {
fn(args, options, (stderr, stdout, code) => {
if (code) {
var cmd = Array.isArray(args) ? args.join(' ') : args;
reject(new Error(cmd + ' returned non zero exit code. Stderr: ' + stderr));
@@ -21,19 +22,6 @@ module.exports = {
});
});
},
execProper: function (args, options) {
options = options || {};
return new Promise((resolve, reject) => {
execProper(args, options, (error, stdout, stderr) => {
if (error != null) {
var cmd = Array.isArray(args) ? args.join(' ') : args;
reject(new Error(cmd + ' returned non zero exit code. Stderr: ' + stderr));
} else {
resolve(stdout);
}
});
});
},
isWindows: function () {
return process.platform === 'win32';
},