From 28e7818c433bc7e04e32729953249b208e69f8b9 Mon Sep 17 00:00:00 2001 From: Aaron Propst Date: Tue, 6 Jun 2017 13:40:18 -0600 Subject: [PATCH 1/4] Offer a more intuitive way to name new containers --- examples/run.js | 27 +++++++++++++++++++++++++++ lib/docker.js | 7 +++++++ 2 files changed, 34 insertions(+) diff --git a/examples/run.js b/examples/run.js index 6967414..61c9aae 100644 --- a/examples/run.js +++ b/examples/run.js @@ -16,5 +16,32 @@ docker.run('ubuntu', [], process.stdout, { 'Binds': ['/home/vagrant:/stuff'], } }, function(err, data, container) { + if (err){ + return console.error(err); + } console.log(data.StatusCode); }); + + + +//run and give a container a name and a label +docker.run('redis', [], process.stdout, { + "Name": 'MyNamedContainer', + "Labels": { + "environment": "blueWhale" + }, + "HostConfig": { + "PortBindings": { + "6379/tcp": [ + { + "HostPort": "0" //Map container to a random unused port. + } + ] + } + } +}, function(err, data, container) { + if (err){ + return console.error(err); + } + console.log(data.StatusCode); +}); \ No newline at end of file diff --git a/lib/docker.js b/lib/docker.js index b794e37..8028f16 100644 --- a/lib/docker.js +++ b/lib/docker.js @@ -42,6 +42,13 @@ var Docker = function(opts) { */ Docker.prototype.createContainer = function(opts, callback) { var self = this; + + //If they specified a container name and they aren't using _query map it for the query string parameter lowercase. + if (typeof opts.Name === 'string' && typeof opts._query === 'undefined'){ + opts._query = { name: opts.Name }; + delete opts.Name; + } + var optsf = { path: '/containers/create?', method: 'POST', From 932e8018805679aedd40a5a75cd8f1312fd9b88c Mon Sep 17 00:00:00 2001 From: Aaron Propst Date: Tue, 6 Jun 2017 13:59:15 -0600 Subject: [PATCH 2/4] tweaking args to not have two runs on stdout --- examples/run.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/run.js b/examples/run.js index 61c9aae..436809d 100644 --- a/examples/run.js +++ b/examples/run.js @@ -25,8 +25,8 @@ docker.run('ubuntu', [], process.stdout, { //run and give a container a name and a label -docker.run('redis', [], process.stdout, { - "Name": 'MyNamedContainer', +docker.run('redis', [], undefined, { + "name": 'MyNamedContainer', "Labels": { "environment": "blueWhale" }, From cefea54f06a209fd073c831509991ce01b478def Mon Sep 17 00:00:00 2001 From: Aaron Propst Date: Fri, 9 Jun 2017 12:03:12 -0600 Subject: [PATCH 3/4] Oops, run example doesn't use the 'Name' case I was trying for. --- examples/run.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/run.js b/examples/run.js index 436809d..c18d546 100644 --- a/examples/run.js +++ b/examples/run.js @@ -26,7 +26,7 @@ docker.run('ubuntu', [], process.stdout, { //run and give a container a name and a label docker.run('redis', [], undefined, { - "name": 'MyNamedContainer', + "Name": 'MyNamedContainer', "Labels": { "environment": "blueWhale" }, From 4e8e01dae7742217176b0507295e55fea66e6d2c Mon Sep 17 00:00:00 2001 From: Aaron Propst Date: Fri, 9 Jun 2017 12:28:11 -0600 Subject: [PATCH 4/4] ditching the name pre-processing --- examples/run.js | 2 +- lib/docker.js | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/examples/run.js b/examples/run.js index c18d546..436809d 100644 --- a/examples/run.js +++ b/examples/run.js @@ -26,7 +26,7 @@ docker.run('ubuntu', [], process.stdout, { //run and give a container a name and a label docker.run('redis', [], undefined, { - "Name": 'MyNamedContainer', + "name": 'MyNamedContainer', "Labels": { "environment": "blueWhale" }, diff --git a/lib/docker.js b/lib/docker.js index 8028f16..b794e37 100644 --- a/lib/docker.js +++ b/lib/docker.js @@ -42,13 +42,6 @@ var Docker = function(opts) { */ Docker.prototype.createContainer = function(opts, callback) { var self = this; - - //If they specified a container name and they aren't using _query map it for the query string parameter lowercase. - if (typeof opts.Name === 'string' && typeof opts._query === 'undefined'){ - opts._query = { name: opts.Name }; - delete opts.Name; - } - var optsf = { path: '/containers/create?', method: 'POST',