Skip to content
This repository has been archived by the owner on Nov 23, 2019. It is now read-only.

ContainerList leaves .Mounts empty #188

Closed
msterin opened this issue Apr 2, 2016 · 4 comments
Closed

ContainerList leaves .Mounts empty #188

msterin opened this issue Apr 2, 2016 · 4 comments

Comments

@msterin
Copy link

msterin commented Apr 2, 2016

I see the following behavior:

  • ContainersList returns all .Mounts empty
  • ContainerInspect fills in all .Mounts properly

Is this expected (or what I am doing wrong) ? And if it is expected, why types.Container even has Mounts []MountPointif it's left empty by ContainerList ?

How to reproduce:
I am running a small test below, which enumerates containers with ContainersList and checks the content of .Mounts, and then does per-container ContainerInspect and checks the content of .Mounts again.

Docker 1.10.3 , Ubuntu 14.04 Kernel 3.13. Engine-API is used via vendoring, taken on March 2

Test run output:

  • Output refcount using List 0 shows there was 0 local mounts (which is wrong, and I did check and .Mounts all have len 0 in the ContainerList resutl)
  • Output refcount using Inspect 103 shows all data volume mounts were accurately counted

The test assumes some containers with local volumes; and your counts will obviously vary

try$ ./mounts_check
2016/04/01 16:40:11 Connected to unix:///var/run/docker.sock
2016/04/01 16:40:14 103 containers found
2016/04/01 16:40:14 total refcount: using List 0 using Inspect 103

Test

//
// A simple check for Container.Mounts content in engine-api
//

package main

import (
    "github.com/docker/engine-api/client"
    "github.com/docker/engine-api/types"
    "log"
)

const (
    apiVersion = "v1.22"
    driverName = "local"
    endPoint   = "unix:///var/run/docker.sock"
)

func main() {
    defaultHeaders := map[string]string{"User-Agent": "engine-api-client-1.0"}

    c, err := client.NewClient(endPoint, apiVersion, nil, defaultHeaders)
    if err != nil {
        log.Printf("Failed to connect to %s, err: %v\n", endPoint, err)
        return
    }

    log.Printf("Connected to %s\n", endPoint)
    containers, err := c.ContainerList(types.ContainerListOptions{
        All: true, Size: true,
    })
    if err != nil {
        log.Printf("Faild to get containers list (err: %v)\n", err)
        return
    }
    log.Printf("%d containers found\n", len(containers))

    refcnt1 := 0
    refcnt2 := 0
    for _, ct := range containers {
        for _, mount := range ct.Mounts {
            if mount.Driver == driverName {
                refcnt1++
            }
        }

        ct_json, err := c.ContainerInspect(ct.ID)
        if err != nil {
            log.Printf("Inspect failed on %s : %v\n", ct.Names, err)
            continue
        } 

        for _, mount := range ct_json.Mounts {
            if mount.Driver == driverName {
                refcnt2++

            }
        }
    }
    log.Printf("total refcount: using List %d using Inspect %d\n", refcnt1, refcnt2)
}
@vdemeester
Copy link
Contributor

@msterin I think it's expected with the 1.10 daemon. The Mount attribute in the types.Container is populated by the daemon in 1.11 (we added Mounts to ps and the possibility to filter using it).

Using a daemon 1.11.0-rc2 :

$ go run est.go 
2016/04/02 10:59:32 Connected to unix:///var/run/docker.sock
2016/04/02 10:59:35 9 containers found
2016/04/02 10:59:35 total refcount: using List 1 using Inspect 1

@msterin
Copy link
Author

msterin commented Apr 4, 2016

@vdemeester - thanks ! It does look sloppy to leave a field selectively filled in by some APIs with zero comments and zero doc, but since it's not my misunderstanding of the API but a bug in 1.10 (fixed in 1.11 per your run) I will just stick with ContainerInspect then.

@msterin msterin closed this as completed Apr 4, 2016
@vdemeester
Copy link
Contributor

It's more about version than a bug, you talking to a 1.10 daemon with a v1.11 api lin'. It's retro compatib!e so it works, but some field don't get filed 😇

@msterin
Copy link
Author

msterin commented Apr 4, 2016

It's more about version than a bug, you talking to a 1.10 daemon with a v1.11 api lin'. It's retro compatib!e so it works, but some field don't get filed

Nice wordsmithing :-) ! On my books, it is still a bug - I am talking to 1.10 with 1.10 API (see below) but it's beyond the point - your post cleared up what's going on so it's all good. Thanks again.

Per https://docs.docker.com/engine/reference/api/docker_remote_api/

Docker version  API version     Changes
1.10.x              1.22         API changes

So I thought I was talking to 1.10 daemon with 1.10 API. .Mounts field was added to engine-API in early February and I picked the code in March. I did not see anything in the 1.22 APi definition which indicates that one API fills the filed in, and another does not.

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

No branches or pull requests

2 participants