-
-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
207 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,37 @@ | ||
var Docker = require('../lib/docker'); | ||
|
||
var docker = new Docker({socketPath: '/var/run/docker.sock'}); | ||
var docker = new Docker({ | ||
socketPath: '/var/run/docker.sock' | ||
}); | ||
|
||
/** | ||
* Get env list from running container | ||
* @param container | ||
*/ | ||
function runExec(container) { | ||
options = { | ||
"AttachStdout": true, | ||
"AttachStderr": true, | ||
"Tty": false, | ||
Cmd: ["env"] | ||
}; | ||
container.exec(options, function (err, data) { | ||
container.execstart(data.Id, function (err, stream) { | ||
if (err != null) { | ||
callback(err, null); | ||
return; | ||
} | ||
|
||
stream.setEncoding('utf8'); | ||
stream.on('data', function (chunk) { | ||
console.log(chunk); | ||
}); | ||
stream.on('end', function () { | ||
console.log('--Done--'); | ||
}); | ||
}); | ||
}) | ||
} | ||
options = { | ||
"AttachStdout": true, | ||
"AttachStderr": true, | ||
"Tty": false, | ||
Cmd: ["env"] | ||
}; | ||
container.exec(options, function(err, exec) { | ||
if (err) return; | ||
|
||
docker.createContainer({Image: 'ubuntu', Cmd: ['/bin/ls', '/stuff'], "Volumes": {"/stuff": {}}}, function (err, container) { | ||
container.attach({stream: true, stdout: true, stderr: true, tty: true}, function (err, stream) { | ||
stream.pipe(process.stdout); | ||
exec.start(function(err, stream) { | ||
if (err) return; | ||
|
||
container.start({"Binds": ["/home/vagrant:/stuff"]}, function (err, data) { | ||
runExec(container); | ||
}); | ||
stream.setEncoding('utf8'); | ||
stream.pipe(process.stdout); | ||
}); | ||
}); | ||
} | ||
|
||
docker.createContainer({ | ||
Image: 'ubuntu', | ||
Cmd: ['/bin/bash'] | ||
}, function(err, container) { | ||
container.start({}, function(err, data) { | ||
runExec(container); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
var _ = require('underscore'); | ||
|
||
/** | ||
* Represents an Exec | ||
* @param {Object} modem docker-modem | ||
* @param {String} id Exec's ID | ||
*/ | ||
var Exec = function(modem, id) { | ||
this.modem = modem; | ||
this.id = id; | ||
}; | ||
|
||
/** | ||
* Start the exec call that was setup. | ||
* | ||
* @param {object} options | ||
* @param {function} callback | ||
*/ | ||
Exec.prototype.start = function(opts, callback) { | ||
if (!callback && typeof(opts) === 'function') { | ||
callback = opts; | ||
opts = {}; | ||
} | ||
|
||
var optsf = { | ||
path: '/exec/' + this.id + '/start', | ||
method: 'POST', | ||
isStream: true, | ||
statusCodes: { | ||
200: true, | ||
404: "no such exec", | ||
500: "container not running" | ||
}, | ||
options: opts | ||
}; | ||
|
||
this.modem.dial(optsf, function(err, data) { | ||
callback(err, data); | ||
}); | ||
}; | ||
|
||
/** | ||
* Resize the exec call that was setup. | ||
* | ||
* @param {object} options | ||
* @param {function} callback | ||
*/ | ||
Exec.prototype.resize = function(opts, callback) { | ||
if (!callback && typeof(opts) === 'function') { | ||
callback = opts; | ||
opts = null; | ||
} | ||
var optsf = { | ||
path: '/exec/' + this.id + '/resize?', | ||
method: 'POST', | ||
statusCodes: { | ||
200: true, | ||
404: "no such exec", | ||
500: "container not running" | ||
}, | ||
options: opts | ||
}; | ||
|
||
this.modem.dial(optsf, function(err, data) { | ||
callback(err, data); | ||
}); | ||
}; | ||
|
||
|
||
module.exports = Exec; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "dockerode", | ||
"description": "Docker.io / Docker remote API implementation.", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"author": "Pedro Dias <[email protected]>", | ||
"maintainers": [ | ||
"apocas <[email protected]>" | ||
|
Oops, something went wrong.