-
-
Save kishorenc/026354f451f544153a2f to your computer and use it in GitHub Desktop.
Dockerode - container creation fails on OS X after 3 times
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
var Docker = require('dockerode'); | |
var docker = new Docker({ host: 'http://localhost', port: 2375 }); | |
var DOCKER_IMAGE = '227971251e9f'; | |
function getContainerOpts(image, cmd) { | |
return { | |
'Hostname': '', | |
'User': '', | |
'AttachStdin': true, | |
'AttachStdout': true, | |
'AttachStderr': true, | |
'Tty': true, | |
'OpenStdin': true, | |
'StdinOnce': false, | |
'Env': null, | |
'Cmd': ['bash'], | |
'Dns': ['8.8.8.8', '8.8.4.4'], | |
'Image': image, | |
'Volumes': {}, | |
'VolumesFrom': '', | |
'DisableNetwork': true, | |
"Memory": 36700160, // 35 MB | |
"MemorySwap":36700160 | |
}; | |
} | |
function init() { | |
var options = getContainerOpts(DOCKER_IMAGE) | |
console.log('before create') | |
// create seems to silently fail after 3 times | |
docker.createContainer(options, function(createErr, container) { | |
if(createErr) console.log(createErr); | |
console.log('Container created with response:', container) | |
var attach_opts = {stream: true, stdin: true, stdout: true, stderr: true} | |
container.attach(attach_opts, function handler(err, stream) { | |
console.log('inside attach'); | |
container.start(function(err, data) { | |
container.wait(function(err, data) { | |
// clean up | |
}); | |
}); | |
}); | |
}); | |
} | |
setInterval(init, 5000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment