{"action":"created","issue":{"url":"https://api.github.com/repos/docker/docker/issues/3778","labels_url":"https://api.github.com/repos/docker/docker/issues/3778/labels{/name}","comments_url":"https://api.github.com/repos/docker/docker/issues/3778/comments","events_url":"https://api.github.com/repos/docker/docker/issues/3778/events","html_url":"https://github.com/docker/docker/issues/3778","id":26332839,"number":3778,"title":"Detect exposed ports from inside container","user":{"login":"drewcrawford","id":183400,"avatar_url":"https://avatars.githubusercontent.com/u/183400?v=3","gravatar_id":"","url":"https://api.github.com/users/drewcrawford","html_url":"https://github.com/drewcrawford","followers_url":"https://api.github.com/users/drewcrawford/followers","following_url":"https://api.github.com/users/drewcrawford/following{/other_user}","gists_url":"https://api.github.com/users/drewcrawford/gists{/gist_id}","starred_url":"https://api.github.com/users/drewcrawford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drewcrawford/subscriptions","organizations_url":"https://api.github.com/users/drewcrawford/orgs","repos_url":"https://api.github.com/users/drewcrawford/repos","events_url":"https://api.github.com/users/drewcrawford/events{/privacy}","received_events_url":"https://api.github.com/users/drewcrawford/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/docker/docker/labels/kind/feature","name":"kind/feature","color":"AAB3AB"},{"url":"https://api.github.com/repos/docker/docker/labels/kind/proposal","name":"kind/proposal","color":"bfe5bf"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":33,"created_at":"2014-01-27T05:44:31Z","updated_at":"2015-07-26T06:28:17Z","closed_at":null,"body":"# What\r\n\r\nThere should be a simple way for a container to detect the portmappings assigned to it.  (from inside the container)\r\n\r\n# Why\r\n\r\nThere are a variety of cases where an application needs to know the *real* external IP address and port at which it can be reached.  Some examples:\r\n\r\n* torrent client\r\n* FTP server (passive mode)\r\n* TeamCity build agent\r\n* others\r\n\r\nThe external IP can be detected reliably through the use of an intermediary.  However the port mappings cannot be reliably automatically detected.\r\n\r\n## Why don't you use non-dynamic ports?\r\n\r\nThe use of static ports (e.g. `docker run -p 1234:1234` syntax), plus hardcoding the same portmappings into the image, allows the container to know what its port mappings are without dynamic discovery.\r\n\r\nHowever this solution does not allow you to run the same image in multiple containers on the same host (as the ports would conflict), which is an important usecase for some images.  It also assumes that the ports baked into the image will never be used by any other docker image that a user is likely to install, which is not a very good assumption.\r\n\r\n## Why don't you use the REST API?\r\n\r\nAllowing a container to have access to the REST API is problematic.  For one thing, the REST API is read/write, and if all you need is to read your portmappings, that's a dangerous level of permissions to grant a container just to find out a few ports.\r\n"},"comment":{"url":"https://api.github.com/repos/docker/docker/issues/comments/124950299","html_url":"https://github.com/docker/docker/issues/3778#issuecomment-124950299","issue_url":"https://api.github.com/repos/docker/docker/issues/3778","id":124950299,"user":{"login":"jp-reads","id":13109770,"avatar_url":"https://avatars.githubusercontent.com/u/13109770?v=3","gravatar_id":"","url":"https://api.github.com/users/jp-reads","html_url":"https://github.com/jp-reads","followers_url":"https://api.github.com/users/jp-reads/followers","following_url":"https://api.github.com/users/jp-reads/following{/other_user}","gists_url":"https://api.github.com/users/jp-reads/gists{/gist_id}","starred_url":"https://api.github.com/users/jp-reads/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jp-reads/subscriptions","organizations_url":"https://api.github.com/users/jp-reads/orgs","repos_url":"https://api.github.com/users/jp-reads/repos","events_url":"https://api.github.com/users/jp-reads/events{/privacy}","received_events_url":"https://api.github.com/users/jp-reads/received_events","type":"User","site_admin":false},"created_at":"2015-07-26T06:28:17Z","updated_at":"2015-07-26T06:28:17Z","body":"+1"}}