Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InspectContainer dose not contain PortBindings info #82

Closed
libin-hdk opened this issue Mar 17, 2014 · 2 comments
Closed

InspectContainer dose not contain PortBindings info #82

libin-hdk opened this issue Mar 17, 2014 · 2 comments

Comments

@libin-hdk
Copy link

My code is here:

type Container struct {
    ID string
        ......
    Volumes   map[string]string
    VolumesRW map[string]bool

    // Add by Li Bin
    HostConfig *HostConfig
}

// Add by Li Bin
func (p *HostConfig) unmarshal(raw json.RawMessage) bool {
    if err := json.Unmarshal(raw, p); err != nil {
        return false
    }
    return true
}

func (c *Client) InspectContainer(id string) (*Container, error) {
    path := "/containers/" + id + "/json"
    body, status, err := c.do("GET", path, nil)
    if status == http.StatusNotFound {
        return nil, &NoSuchContainer{ID: id}
    }
    if err != nil {
        return nil, err
    }
    var container Container
    err = json.Unmarshal(body, &container)
    if err != nil {
        return nil, err
    }

     // Add by Li Bin
    var doc struct {
        Things []json.RawMessage `json:"things"`
    }
    err = json.Unmarshal(body, &doc)
    if err != nil {
        return nil, err
    }
    for _, thing := range doc.Things {
        host := new(HostConfig)
        if host.unmarshal(thing) {
            container.HostConfig = host
        }
    }

    return &container, nil
}
@andrewsmedina
Copy link
Collaborator

The PortBindings is returned by Container.NetworkSettings https://github.com/fsouza/go-dockerclient/blob/master/container.go#L195

@libin-hdk
Copy link
Author

Got it, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants