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
ListContainers fails listing all containers #85
Comments
it fails in line 63 of container.go err = json.Unmarshal(body, &containers) I had to connect directly to docker, reusing the code of the client API and http |
@DimShadoWWW looks like Docker has changed the API, I will have a look. It seems that you managed to get it working, what did you do? Would you be willing to send a patch? Thanks! |
@fsouza .. this is the code of my function (I hasn't clean or organized yet): func (l *Lib) GetContainers(all bool) ([]APIContainers, error) {
query := "0"
if all {
query = "1"
}
req, err := http.NewRequest("GET", "/containers/json?all="+query, nil)
if err != nil {
fmt.Errorf("ERROR: ", err)
return nil, err
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", "mine")
var resp *http.Response
dial, err := net.Dial("unix", "/var/run/docker.sock")
if err != nil {
fmt.Errorf("ERROR: ", err)
return nil, err
}
clientconn := httputil.NewClientConn(dial, nil)
resp, err = clientconn.Do(req)
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Errorf("ERROR: ", err)
return nil, err
}
outs := engine.NewTable("Created", 0)
if _, err := outs.ReadListFrom(body); err != nil {
fmt.Errorf("ERROR: ", err)
return nil, err
}
var containers []APIContainers
for _, out := range outs.Data {
var c APIContainers
c.ID = out.Get("Id")
c.Names = out.GetList("Names")
c.Image = out.Get("Image")
c.Command = out.Get("Command")
c.Created = out.GetInt64("Created")
c.Status = out.Get("Status")
c.SizeRw = out.GetInt64("SizeRw")
c.SizeRootFs = out.GetInt64("SizeRootFs")
ports := engine.NewTable("", 0)
ports.ReadListFrom([]byte(out.Get("Ports")))
ports.SetKey("PublicPort")
ports.Sort()
for _, port := range ports.Data {
var p APIPort
p.IP = port.Get("IP")
p.PrivatePort = port.GetInt64("PrivatePort")
p.PublicPort = port.GetInt64("PublicPort")
p.Type = port.Get("Type")
c.Ports = append(c.Ports, p)
}
containers = append(containers, c)
}
return containers, nil
} |
It's working with the latest version of Docker. I've tried Docker 1.0 and 1.1. I'm closing this issue. @DimShadoWWW please let me know if you find this or any other issue in the future! :) |
ListContainers with "docker.ListContainersOptions{All: true}" returns an empty list
while "docker.ListContainersOptions{All: false}" or "docker.ListContainersOptions{}"
returns the list of containers running
I'm using docker version 0.9.0.
my code:
The text was updated successfully, but these errors were encountered: