{"action":"created","issue":{"url":"https://api.github.com/repos/fsouza/go-dockerclient/issues/220","labels_url":"https://api.github.com/repos/fsouza/go-dockerclient/issues/220/labels{/name}","comments_url":"https://api.github.com/repos/fsouza/go-dockerclient/issues/220/comments","events_url":"https://api.github.com/repos/fsouza/go-dockerclient/issues/220/events","html_url":"https://github.com/fsouza/go-dockerclient/issues/220","id":58151827,"number":220,"title":"PortBinding does not work and go-dockerclient debugging","user":{"login":"knodir","id":1505903,"avatar_url":"https://avatars.githubusercontent.com/u/1505903?v=3","gravatar_id":"","url":"https://api.github.com/users/knodir","html_url":"https://github.com/knodir","followers_url":"https://api.github.com/users/knodir/followers","following_url":"https://api.github.com/users/knodir/following{/other_user}","gists_url":"https://api.github.com/users/knodir/gists{/gist_id}","starred_url":"https://api.github.com/users/knodir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/knodir/subscriptions","organizations_url":"https://api.github.com/users/knodir/orgs","repos_url":"https://api.github.com/users/knodir/repos","events_url":"https://api.github.com/users/knodir/events{/privacy}","received_events_url":"https://api.github.com/users/knodir/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-02-19T00:32:21Z","updated_at":"2015-08-06T02:02:01Z","closed_at":null,"body":"Hi,\r\n\r\nI am trying to run `google/cadvisor` image via `go-dockerclient`. Here is the shell command to do this:\r\n\r\n```shell\r\nsudo docker run --volume=/var/run:/var/run:rw --volume=/sys:/sys:ro --volume=/var/lib/docker/:/var/lib/docker:ro --publish=8080:8080 --detach=true --name=cadvisor google/cadvisor\r\n```\r\n\r\nIt gives following output on success:\r\n\r\n```shell\r\nsudo docker ps\r\nCONTAINER ID        IMAGE                   COMMAND               CREATED             STATUS              PORTS                    NAMES\r\na7896c6cae43        google/cadvisor:0.9.0   \"/usr/bin/cadvisor\"   50 seconds ago       Up 49 seconds        0.0.0.0:8080->8080/tcp   cadvisor\r\n```\r\n\r\nI wrote a program to do this with `go-dockerclient`, which successfully creates the container, but without port mapping (note the `PORTS: 0.0.0.0:8080->8080/tcp` on above shell output). Here is the code I am running\r\n\r\n```go\r\npackage main\r\n\r\nimport (\r\n\t\"fmt\"\r\n    \"github.com/fsouza/go-dockerclient\"\r\n)\r\n\r\nfunc main() {\r\n    endpoint := \"unix:///var/run/docker.sock\"\r\n    client, _ := docker.NewClient(endpoint)\r\n\r\n    exposedCadvPort := map[docker.Port]struct{}{\r\n        \"8080/tcp\": {}}\r\n\r\n    createContConf := docker.Config{\r\n        ExposedPorts: exposedCadvPort,\r\n        Image: \"google/cadvisor\"}\r\n\r\n    volumesToMount := []string{\r\n        \"/var/run\", \"/var/run:rw\", \r\n        \"/sys\", \"/sys:ro\", \r\n        \"/var/lib/docker/\", \"/var/lib/docker:ro\"}\r\n\r\n    portBindings := map[docker.Port][]docker.PortBinding{\r\n        \"8080/tcp\": []docker.PortBinding{docker.PortBinding{HostPort: \"8080\"}}}\r\n\r\n    createContHostConfig := docker.HostConfig{\r\n        PortBindings: portBindings,\r\n        PublishAllPorts: true,\r\n        Privileged: false,\r\n        VolumesFrom: volumesToMount}\r\n\r\n    createContOps := docker.CreateContainerOptions{\r\n        Name: \"cadvisor\",\r\n        Config: &createContConf,\r\n        HostConfig: &createContHostConfig}\r\n\r\n    cont, _ := client.CreateContainer(createContOps)\r\n    fmt.Printf(\"\\ncontainer = %s\\n\", cont)\r\n}\r\n```\r\n\r\nAnd its output\r\n```shell\r\nsudo docker ps -a\r\nCONTAINER ID        IMAGE                   COMMAND               CREATED             STATUS              PORTS               NAMES\r\neeedaac903e9        google/cadvisor:0.9.0   \"/usr/bin/cadvisor\"   17 minutes ago                                              cadvisor \r\n```\r\n\r\nI tweaked `PortBindings` in several different ways, but still fail to create the container with correct port mapping. Can you please point what I am doing wrong?\r\n\r\nI have couple of other questions, if I may ask. \r\n\r\nI don't understand the relationship between [Config.ExposedPorts](https://github.com/fsouza/go-dockerclient/blob/master/container.go#L183) and [HostConfig.PortBindings](https://github.com/fsouza/go-dockerclient/blob/master/container.go#L355). Should `PortBindings` provide mapping for ports listed on `ExposedPorts`? I mostly referred to the [Docker remote API](https://docs.docker.com/reference/api/docker_remote_api_v1.15/#create-a-container), which maps `\"ExposedPorts\": {\"22/tcp\": {}}` to `\"PortBindings\": { \"22/tcp\": [{ \"HostPort\": \"11022\" }] },`. If this understanding is correct, should I be using `\"ExposedPorts\": {\"8080/http\": {}}` and `\"PortBindings\": { \"8080/http\": [{ \"HostPort\": \"8080\" }] },` for cAdvisor example (as I'd be pointing the browser to `localhost:8080` to see cAdvisor's output)?\r\n\r\nIs there way to see `go-dockerclient`'s `POST` message before calling `client.CreateContainer`? Right now I can't tell if there is a problem in the message `go-dockerclient` is sending, or remote Docker daemon doing something wrong (due to version difference, etc.)? One way to debug this would be to see if my `POST` complies with [Docker remote API](https://docs.docker.com/reference/api/docker_remote_api_v1.15/#create-a-container). It would be great to have such feature (or something similar).\r\n\r\nThanks,\r\nNodir."},"comment":{"url":"https://api.github.com/repos/fsouza/go-dockerclient/issues/comments/128211041","html_url":"https://github.com/fsouza/go-dockerclient/issues/220#issuecomment-128211041","issue_url":"https://api.github.com/repos/fsouza/go-dockerclient/issues/220","id":128211041,"user":{"login":"bzz","id":5582506,"avatar_url":"https://avatars.githubusercontent.com/u/5582506?v=3","gravatar_id":"","url":"https://api.github.com/users/bzz","html_url":"https://github.com/bzz","followers_url":"https://api.github.com/users/bzz/followers","following_url":"https://api.github.com/users/bzz/following{/other_user}","gists_url":"https://api.github.com/users/bzz/gists{/gist_id}","starred_url":"https://api.github.com/users/bzz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bzz/subscriptions","organizations_url":"https://api.github.com/users/bzz/orgs","repos_url":"https://api.github.com/users/bzz/repos","events_url":"https://api.github.com/users/bzz/events{/privacy}","received_events_url":"https://api.github.com/users/bzz/received_events","type":"User","site_admin":false},"created_at":"2015-08-06T02:02:01Z","updated_at":"2015-08-06T02:02:01Z","body":"Stuck with the same issue. Do you guys have any updates on how to overcome it?\r\n\r\nI used docker 1.4.1 over REST API \\w `docker.PortBinding{HostIP: \"0.0.0.0\", HostPort: \"8080\"},` and on get `docker inspect` get\r\n\r\n```\r\n      \"PortMapping\": null,\r\n        \"Ports\": {\r\n            \"8080/tcp\": null\r\n        }\r\n```\r\nas well as for `docker ps`  \r\n```\r\n21eb69777ec3        ...:latest   \"/bin/bash -c /usr/l   About a minute ago   Up 59 seconds       8080/tcp            containerName\r\n```\r\n\r\nAppreciate your help!"}}