moby / moby

The Moby Project - a collaborative project for the container ecosystem to assemble container-based systems
https://mobyproject.org/
Apache License 2.0
68.64k stars 18.64k forks source link

Returned container count is invalid for images API #34005

Open G07cha opened 7 years ago

G07cha commented 7 years ago

Description

On querying images list each image list will be having Containers property with value -1 regardless of amount of containers using this image.

Steps to reproduce the issue:

  1. Run container from the image(for example docker run -ti ubuntu bash)
  2. Get list of images from the API(curl --unix-socket /var/run/docker.sock "http:/v1.30/images/json")

Describe the results you received:

"ubuntu" image has Containers property with value -1.

Describe the results you expected:

Containers property with value 1

Output of docker version:

Client:
 Version:      17.06.0-ce
 API version:  1.30
 Go version:   go1.8.3
 Git commit:   02c1d87
 Built:        Fri Jun 23 21:31:53 2017
 OS/Arch:      darwin/amd64

Server:
 Version:      17.06.0-ce
 API version:  1.30 (minimum version 1.12)
 Go version:   go1.8.3
 Git commit:   02c1d87
 Built:        Fri Jun 23 21:51:55 2017
 OS/Arch:      linux/amd64
 Experimental: true

Output of docker info:

Containers: 4
 Running: 2
 Paused: 0
 Stopped: 2
Images: 40
Server Version: 17.06.0-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host ipvlan macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: cfb82a876ecc11b5ca0977d1733adbe58599088a
runc version: 2d41c047c83e09a6d61d464906feb2a2f3c52aa4
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.31-moby
Operating System: Alpine Linux v3.5
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.952GiB
Name: moby
ID: QN2D:44BC:EQ5U:GCN2:Z2XT:DSNU:GGTI:FNKB:MHAJ:3I7E:ASHB:RJTT
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 34
 Goroutines: 48
 System Time: 2017-07-07T10:18:20.598658487Z
 EventsListeners: 1
No Proxy: *.local, 169.254/16
Registry: https://index.docker.io/v1/
Experimental: true
Insecure Registries:
 jenkin-registry.gsintlab.com
 127.0.0.0/8
Live Restore Enabled: false
thaJeztah commented 7 years ago

This looks like a documentation issue; the Containers count is only propagated for the /system/df endpoint https://docs.docker.com/engine/api/v1.30/#operation/SystemDataUsage, which uses the same backend, but fetches additional properties; https://github.com/moby/moby/blob/950d472c9ce4180b80e28030f7de68ffc3254f97/daemon/images.go#L192-L221

deviantony commented 7 years ago

So what's the goal of that Containers field in the Image object if it can only be retrieved using the system/df endpoint?