{"action":"created","issue":{"url":"https://api.github.com/repos/apocas/dockerode/issues/257","repository_url":"https://api.github.com/repos/apocas/dockerode","labels_url":"https://api.github.com/repos/apocas/dockerode/issues/257/labels{/name}","comments_url":"https://api.github.com/repos/apocas/dockerode/issues/257/comments","events_url":"https://api.github.com/repos/apocas/dockerode/issues/257/events","html_url":"https://github.com/apocas/dockerode/issues/257","id":159384591,"number":257,"title":"Mapping Ports through Dockerode.","user":{"login":"cefn","id":159819,"avatar_url":"https://avatars.githubusercontent.com/u/159819?v=3","gravatar_id":"","url":"https://api.github.com/users/cefn","html_url":"https://github.com/cefn","followers_url":"https://api.github.com/users/cefn/followers","following_url":"https://api.github.com/users/cefn/following{/other_user}","gists_url":"https://api.github.com/users/cefn/gists{/gist_id}","starred_url":"https://api.github.com/users/cefn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cefn/subscriptions","organizations_url":"https://api.github.com/users/cefn/orgs","repos_url":"https://api.github.com/users/cefn/repos","events_url":"https://api.github.com/users/cefn/events{/privacy}","received_events_url":"https://api.github.com/users/cefn/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-06-09T11:22:03Z","updated_at":"2016-06-17T11:43:47Z","closed_at":null,"body":"I am able to launch containers and map their ports from the CLI. However, the same thing seems impossible through the Remote API.\r\n\r\nI must be missing something about how Dockerode passes arguments on to the Remote API. Any suggestions?\r\n\r\nI have tried every combination I can think of, and have followed configurations which are reported to work, referring to...\r\n\r\n* https://medium.com/@kevanahlquist/docker-remote-api-port-bindings-example-b55bc5194e20#.t9hlxlpsg\r\n* http://stackoverflow.com/questions/20428302/binding-a-port-to-a-host-interface-using-the-rest-api/20429133\r\n* https://groups.google.com/forum/#!searchin/docker-user/port$20redirection/docker-user/aHbNFACcTfs/nLY-oUihEAIJ\r\n* https://github.com/docker/docker/issues/3039\r\n\r\nHowever, I am unable to connect over TCP to my service when launched via dockerode, which IS addressable when launched via docker CLI run.\r\n\r\nThe CLI version is...\r\n\r\n```bash\r\ndocker run -it -p 3000:3000 -p 1883:1883 -e DBHOST=$(ifconfig $(route -n get $(docker-machine ip default) | grep interface: | awk '{print $2}') | grep inet | awk '{print $2}') -v /Users/cefn/Documents/code/imagination/git/ifi/impl/releases/keynote/0.1.0:/opt/ifi ifihost bash -c \"nodejs /opt/ifi/lib/ifi/app.js\"\r\n```\r\n\r\nThe Remote API version via dockerode, (which reports 'Promise Success' indicating it has launched, and spits out the same service logging to the console as the CLI version), is...\r\n\r\n```javascript\r\nvar _ = require(\"lodash\"),\r\n    fs = require(\"fs\"),\r\n    os = require(\"os\"),\r\n    dockermachine = require(\"dockermachine\"),\r\n    dockerode = require(\"dockerode\");\r\n\r\nvar selfIp = _.chain(os.networkInterfaces()).values().flatten().filter(function(val){ return (val.family == 'IPv4' && val.internal == false); }).map(\"address\").first().value();\r\n\r\n//var dbHost = selfIp;\r\nvar dbHost = \"192.168.99.1\";\r\n\r\nvar createOptions = {\r\n    Image:\"ifihost\",\r\n    Tty:true,\r\n    ExposedPorts: {\r\n        \"3000/tcp:\": {},\r\n        \"1883/tcp:\": {}\r\n    },\r\n    Env:[\r\n        \"DBHOST=\" + dbHost,\r\n    ],\r\n    Cmd:[\r\n        \"/bin/bash\", \"-c\", \"nodejs /opt/ifi/lib/ifi/app.js\"\r\n    ],\r\n    HostConfig:{\r\n        Binds: [\"/Users/cefn/Documents/code/imagination/git/ifi/impl/releases/keynote/0.1.0:/opt/ifi\"],\r\n    },\r\n};\r\n\r\nvar startOptions = {\r\n    PortBindings: {\r\n        \"3000/tcp\": [{\r\n            \"HostIP\":\"0.0.0.0\",\r\n            \"HostPort\": \"3000\"\r\n        }],\r\n        \"1883/tcp\": [{\r\n            \"HostIP\":\"0.0.0.0\",\r\n            \"HostPort\": \"1883\"\r\n        }],\r\n    },\r\n};\r\n\r\nvar dockerPromise = dockermachine.inspect(\"default\")\r\n    .then(function(info){ //connects to the docker host\r\n        var docker = new dockerode({\r\n            host:info.Driver.IPAddress,\r\n            port:2376,\r\n            ca:fs.readFileSync(info.HostOptions.AuthOptions.CaCertPath),\r\n            cert:fs.readFileSync(info.HostOptions.AuthOptions.ClientCertPath),\r\n            key:fs.readFileSync(info.HostOptions.AuthOptions.ClientKeyPath),\r\n        });\r\n        return docker;\r\n    })\r\n    .then(function(docker){\r\n\r\n        //brings up a new docker guest\r\n        var creationPromise = new Promise(function(resolve, reject){\r\n            docker.createContainer(createOptions, function(err, result){\r\n                if(err) reject(err);\r\n                else resolve(docker.getContainer(result.id));\r\n            });\r\n        });\r\n\r\n        var streamPromise = creationPromise.then(function(container){\r\n            container.attach({stream: true, stdout: true, stderr: true}, function (err, stream) {\r\n                stream.pipe(process.stdout);\r\n            });\r\n        });\r\n\r\n        var executionPromise = creationPromise.then(function(container){\r\n            return new Promise(function(resolve, reject){\r\n                container.start(startOptions, function(err, data){\r\n                    if(err) reject(err);\r\n                    else resolve(data);\r\n                });\r\n            });\r\n        });\r\n\r\n        return executionPromise;\r\n\r\n    })\r\n    .then(function(result){\r\n        console.log(\"Promise Success\");\r\n    })\r\n    .catch(function(err){\r\n        console.log(\"Promise Failure\");\r\n    });\r\n```\r\n\r\nI have looked at the detail of the [Go schema spec for the Remote API](https://godoc.org/github.com/docker/engine-api) and I should even be able to pass PortBindings through on container create in the HostConfig value I believe, but this doesn't work either, so I've resorted to separating the create config and the start config as indicated in the various issues linked above.\r\n\r\nIn each case, when I try to connect to the dockerode-launched version it reports like this...\r\n\r\n```bash\r\n$ mosquitto_sub -h 192.168.99.100 -t '#' -v\r\nError: Connection refused\r\n```\r\n\r\n...where the container launched using docker CLI run allows mosquitto to connect properly with exactly the same invocation (mosquitto implicitly uses port 1883 as default MQTT port)."},"comment":{"url":"https://api.github.com/repos/apocas/dockerode/issues/comments/226748698","html_url":"https://github.com/apocas/dockerode/issues/257#issuecomment-226748698","issue_url":"https://api.github.com/repos/apocas/dockerode/issues/257","id":226748698,"user":{"login":"cefn","id":159819,"avatar_url":"https://avatars.githubusercontent.com/u/159819?v=3","gravatar_id":"","url":"https://api.github.com/users/cefn","html_url":"https://github.com/cefn","followers_url":"https://api.github.com/users/cefn/followers","following_url":"https://api.github.com/users/cefn/following{/other_user}","gists_url":"https://api.github.com/users/cefn/gists{/gist_id}","starred_url":"https://api.github.com/users/cefn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cefn/subscriptions","organizations_url":"https://api.github.com/users/cefn/orgs","repos_url":"https://api.github.com/users/cefn/repos","events_url":"https://api.github.com/users/cefn/events{/privacy}","received_events_url":"https://api.github.com/users/cefn/received_events","type":"User","site_admin":false},"created_at":"2016-06-17T11:43:47Z","updated_at":"2016-06-17T11:43:47Z","body":"Any suggestions how the ```-p 1883:1883``` differs from the Dockerode equivalent PortBindings and ExposedPorts invocation above to try and open the same ports? \r\n\r\nThe CLI version works, the Dockerode version doesn't, with the same Docker host (Docker Machine on OS X). \r\n\r\nA simplified test case demonstrating the same problem is also now provided at...\r\nhttps://github.com/docker/docker/issues/23432 "}}
{"actor":{"display_login":"cefn"}}