{"action":"created","issue":{"url":"https://api.github.com/repos/docker/docker/issues/17476","labels_url":"https://api.github.com/repos/docker/docker/issues/17476/labels{/name}","comments_url":"https://api.github.com/repos/docker/docker/issues/17476/comments","events_url":"https://api.github.com/repos/docker/docker/issues/17476/events","html_url":"https://github.com/docker/docker/pull/17476","id":113995180,"number":17476,"title":"Fix connect to host and prevent disconnect from host for host network","user":{"login":"coolljt0725","id":8232360,"avatar_url":"https://avatars.githubusercontent.com/u/8232360?v=3","gravatar_id":"","url":"https://api.github.com/users/coolljt0725","html_url":"https://github.com/coolljt0725","followers_url":"https://api.github.com/users/coolljt0725/followers","following_url":"https://api.github.com/users/coolljt0725/following{/other_user}","gists_url":"https://api.github.com/users/coolljt0725/gists{/gist_id}","starred_url":"https://api.github.com/users/coolljt0725/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coolljt0725/subscriptions","organizations_url":"https://api.github.com/users/coolljt0725/orgs","repos_url":"https://api.github.com/users/coolljt0725/repos","events_url":"https://api.github.com/users/coolljt0725/events{/privacy}","received_events_url":"https://api.github.com/users/coolljt0725/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/docker/docker/labels/group/networking","name":"group/networking","color":"F6FBFF"},{"url":"https://api.github.com/repos/docker/docker/labels/status/2-code-review","name":"status/2-code-review","color":"fad8c7"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/docker/docker/milestones/45","html_url":"https://github.com/docker/docker/milestones/1.9.1","labels_url":"https://api.github.com/repos/docker/docker/milestones/45/labels","id":1385783,"number":45,"title":"1.9.1","description":"","creator":{"login":"tiborvass","id":827131,"avatar_url":"https://avatars.githubusercontent.com/u/827131?v=3","gravatar_id":"","url":"https://api.github.com/users/tiborvass","html_url":"https://github.com/tiborvass","followers_url":"https://api.github.com/users/tiborvass/followers","following_url":"https://api.github.com/users/tiborvass/following{/other_user}","gists_url":"https://api.github.com/users/tiborvass/gists{/gist_id}","starred_url":"https://api.github.com/users/tiborvass/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tiborvass/subscriptions","organizations_url":"https://api.github.com/users/tiborvass/orgs","repos_url":"https://api.github.com/users/tiborvass/repos","events_url":"https://api.github.com/users/tiborvass/events{/privacy}","received_events_url":"https://api.github.com/users/tiborvass/received_events","type":"User","site_admin":false},"open_issues":13,"closed_issues":34,"state":"open","created_at":"2015-10-30T17:08:02Z","updated_at":"2015-11-09T19:08:31Z","due_on":"2015-11-10T05:00:00Z","closed_at":null},"comments":12,"created_at":"2015-10-29T07:26:12Z","updated_at":"2015-11-09T19:14:16Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/docker/docker/pulls/17476","html_url":"https://github.com/docker/docker/pull/17476","diff_url":"https://github.com/docker/docker/pull/17476.diff","patch_url":"https://github.com/docker/docker/pull/17476.patch"},"body":"There are two commits in this PR.\r\nThe first one is to fix connect to host. If a container start with default network(`bridge`) or `none`\r\nit can't be connect to `host` as desired. but if disconnect the container from `bridge` or `none`, you can\r\nconnect to `host`, but this will cause some problem.\r\n<pre><code>$ docker run -ti --rm --name container1 busybox\r\n$ docker network disconnect bridge container1\r\n$ docker network connect host container1\r\n</code></pre>\r\nwe able to connect to host after the container disconnect from `bridge`\r\nbut actually, the container still use its own network namespace, docker inspect still show its own private sandbox the container use and `ifconfig` in the container still the information of its own private network namespace. \r\nFrom what I understand the container has private network namespace cannot connect to other network namespace, https://github.com/docker/docker/blob/master/daemon/container_unix.go#L742 is supposed to do thar but may not go there because `container.NetworkSettings.Networks` could be nil ,correct me if I'm wrong :) @mavenugo \r\n\r\nThe second commit is to prevent from disconnecting from host for a container start with `--net=host`. if a container with `--net=host` disconnect from `host`,  it still in the host network namespace, but able to connect to other network, and cause some problem.\r\n<pre><code>\r\n$ docker run -ti --rm --net=host --name container1 busybox\r\n$ docker network disconnect host container1\r\n$ docker network connect bridge container1\r\nError response from daemon: failed to set gateway while updating gateway: network is unreachable\r\n</code></pre>\r\nthough connect to `bridge` failed, but it has create a `eth0` network interface on my host\r\n<pre><code>eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500\r\n        inet 172.17.0.2  netmask 255.255.0.0  broadcast 0.0.0.0\r\n        inet6 fe80::42:acff:fe11:2  prefixlen 64  scopeid 0x20<link>\r\n        ether 02:42:ac:11:00:02  txqueuelen 0  (Ethernet)\r\n        RX packets 8  bytes 648 (648.0 B)\r\n        RX errors 0  dropped 0  overruns 0  frame 0\r\n        TX packets 10  bytes 732 (732.0 B)\r\n        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0</code></pre>\r\nand docker inspect show the endpoint information\r\n<pre><code>\"Networks\": {\r\n            \"bridge\": {\r\n                \"EndpointID\": \"ddc8cd9e738f9255fc3288c82d77adf6d226ed1ec0e1c8000935b0269e39080a\",\r\n                \"Gateway\": \"\",\r\n                \"IPAddress\": \"172.17.0.2\",\r\n                \"IPPrefixLen\": 16,\r\n                \"IPv6Gateway\": \"\",\r\n                \"GlobalIPv6Address\": \"\",\r\n                \"GlobalIPv6PrefixLen\": 0,\r\n                \"MacAddress\": \"02:42:ac:11:00:02\"\r\n            }\r\n        }</code></pre> \r\n\r\nSo I think we should prevent user from disconnect from host  \r\nping @tiborvass \r\n"},"comment":{"url":"https://api.github.com/repos/docker/docker/issues/comments/155160372","html_url":"https://github.com/docker/docker/pull/17476#issuecomment-155160372","issue_url":"https://api.github.com/repos/docker/docker/issues/17476","id":155160372,"user":{"login":"calavera","id":1050,"avatar_url":"https://avatars.githubusercontent.com/u/1050?v=3","gravatar_id":"","url":"https://api.github.com/users/calavera","html_url":"https://github.com/calavera","followers_url":"https://api.github.com/users/calavera/followers","following_url":"https://api.github.com/users/calavera/following{/other_user}","gists_url":"https://api.github.com/users/calavera/gists{/gist_id}","starred_url":"https://api.github.com/users/calavera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/calavera/subscriptions","organizations_url":"https://api.github.com/users/calavera/orgs","repos_url":"https://api.github.com/users/calavera/repos","events_url":"https://api.github.com/users/calavera/events{/privacy}","received_events_url":"https://api.github.com/users/calavera/received_events","type":"User","site_admin":false},"created_at":"2015-11-09T19:14:16Z","updated_at":"2015-11-09T19:14:16Z","body":"LGTM.\r\n\r\nUnfortunately, this won't merge cleanly in the 1.9 release branch. @tiborvass should we open a new PR against that branch with a similar fix?"}}