docker / cli

The Docker CLI
Apache License 2.0
4.87k stars 1.91k forks source link

dangling=false filter includes dangling images #4159

Open andrewnicols opened 1 year ago

andrewnicols commented 1 year ago

Description

Documentation for docker images suggests that the dangling flag accetps a boolean with either true or false.

The example given is:

docker images --filter "dangling=true"

This appears to work as expected.

However, if I want to list all images and to exclude the dangling images, I expect to be able to run:

docker images --filter "dangling=false"

Unfortunatel this lists the same results as not specifying a filter at all.

Reproduce

docker images --filter "dangling=false"

Expected behavior

Only images which are not dangling should be shown.

docker version

➜  ~ docker version
Client:
 Cloud integration: v1.0.29
 Version:           20.10.22
 API version:       1.41
 Go version:        go1.18.9
 Git commit:        3a2c30b
 Built:             Thu Dec 15 22:28:41 2022
 OS/Arch:           darwin/arm64
 Context:           default
 Experimental:      true

Server: Docker Desktop 4.16.2 (95914)
 Engine:
  Version:          20.10.22
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.9
  Git commit:       42c8b31
  Built:            Thu Dec 15 22:25:43 2022
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.6.14
  GitCommit:        9ba4b250366a5ddde94bb7c9d1def331423aa323
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

docker info

➜  ~ docker info
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.10.0)
  compose: Docker Compose (Docker Inc., v2.15.1)
  dev: Docker Dev Environments (Docker Inc., v0.0.5)
  extension: Manages Docker extensions (Docker Inc., v0.2.17)
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
  scan: Docker Scan (Docker Inc., v0.23.0)

Server:
 Containers: 105
  Running: 39
  Paused: 0
  Stopped: 66
 Images: 143
 Server Version: 20.10.22
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc io.containerd.runc.v2 io.containerd.runtime.v1.linux
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 9ba4b250366a5ddde94bb7c9d1def331423aa323
 runc version: v1.1.4-0-g5fd4c4d
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.15.49-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: aarch64
 CPUs: 6
 Total Memory: 19.52GiB
 Name: docker-desktop
 ID: KVZU:YLKB:SLOO:SLBQ:YEX7:K3KP:SWQO:WEBH:IIFO:OU6U:6HYE:63NG
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5000
  127.0.0.0/8
 Live Restore Enabled: false

Additional Info

No response

sam-thibault commented 1 year ago

@vvoland @dvdksn can you take a look?

dvdksn commented 1 year ago

I'm not able to reproduce. docker images --filter "dangling=false" produces the correct results for me on both Docker Engine 20.10.22 and 23.0.2

@vvoland any better luck for you?

/ws # docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
<none>       <none>    bdf118602984   2 seconds ago   7.46MB
alpine       latest    51e60588ff2c   12 days ago     7.46MB
/ws # docker images --filter "dangling=false"
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
alpine       latest    51e60588ff2c   12 days ago   7.46MB
/ws # docker images --filter "dangling=true"
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
<none>       <none>    bdf118602984   36 seconds ago   7.46MB
andrewnicols commented 1 year ago

I'm only able to reproduce this for certain images, for example in the following there are two images which have a repository, but no tag. These are listed in both filter options.

In the output below, the following images are listed for both filter options:

moodlehq/moodle-php-apache                                <none>                                                                       51a86feb574c   4 months ago    586MB
moodlehq/bigbluebutton_mock                               <none>                                                                       869ef21f087a   14 months ago   572MB

Heres' the full output:

➜  ~ docker images --filter dangling=false | grep moodlehq
moodlehq/moodle-php-apache                                8.1                                                                          653779f19180   7 days ago      779MB
moodlehq/moodle-php-apache                                dev                                                                          be14b5b13fb6   3 weeks ago     578MB
moodlehq/moodle-db-mssql                                  latest                                                                       78edd1734dd4   4 weeks ago     1.47GB
moodlehq/moodle-php-apache                                8.2                                                                          d51a1abb41aa   2 months ago    591MB
moodlehq/moodle-php-apache                                8.0                                                                          1f58827914fc   2 months ago    582MB
moodlehq/moodle-exttests                                  latest                                                                       e830958c5f7e   2 months ago    369MB
moodlehq/moodleapp                                        latest                                                                       26a7cac0d676   3 months ago    69.5MB
moodlehq/moodle-php-apache                                <none>                                                                       51a86feb574c   4 months ago    586MB
moodlehq/bigbluebutton_mock                               latest                                                                       065ebc5610ff   5 months ago    562MB
moodlehq/moodle-db-oracle-r2                              21                                                                           370fdfed88ed   9 months ago    2.07GB
moodlehq/bigbluebutton_mock                               <none>                                                                       869ef21f087a   14 months ago   572MB
moodlehq/selenium-standalone-chrome                       96.0-moodlehq                                                                bc6f1b34dae9   16 months ago   1.39GB
moodlehq/moodle-db-mssql                                  2017-latest                                                                  90db0e5a355c   19 months ago   1.37GB
➜  ~ docker images --filter dangling=true
REPOSITORY                    TAG       IMAGE ID       CREATED         SIZE
<none>                        <none>    1c33e09d5b5f   3 weeks ago     579MB
<none>                        <none>    9c7155251ce2   3 weeks ago     579MB
<none>                        <none>    b23121bac690   3 weeks ago     579MB
<none>                        <none>    8303d5dfad80   3 weeks ago     579MB
<none>                        <none>    43c3d135d08f   3 weeks ago     579MB
<none>                        <none>    99069da93375   3 weeks ago     579MB
<none>                        <none>    b8d271760a51   3 weeks ago     573MB
<none>                        <none>    334083a39b69   7 weeks ago     135MB
<none>                        <none>    2a316caa1e3f   7 weeks ago     135MB
<none>                        <none>    74ac1b7e7762   7 weeks ago     135MB
<none>                        <none>    5dc360c585c2   7 weeks ago     135MB
<none>                        <none>    039fb400a8a0   7 weeks ago     135MB
<none>                        <none>    4d29c2a40f72   7 weeks ago     135MB
<none>                        <none>    ab4c57be962e   7 weeks ago     135MB
<none>                        <none>    8279fd491827   7 weeks ago     558MB
<none>                        <none>    0ae702f580f5   7 weeks ago     558MB
<none>                        <none>    7fc9b939390a   7 weeks ago     558MB
<none>                        <none>    938c38c05f5c   7 weeks ago     558MB
<none>                        <none>    ad83e9fa2ec0   7 weeks ago     558MB
<none>                        <none>    f278dae150e9   7 weeks ago     558MB
<none>                        <none>    6b73829b0c3f   7 weeks ago     558MB
<none>                        <none>    c85ed58dc9eb   8 weeks ago     7.46MB
<none>                        <none>    c5bbae33024c   8 weeks ago     7.46MB
<none>                        <none>    9b4fd1d7e234   8 weeks ago     7.46MB
moodlehq/moodle-php-apache    <none>    51a86feb574c   4 months ago    586MB
<none>                        <none>    238adb7c8709   6 months ago    774MB
moodlehq/bigbluebutton_mock   <none>    869ef21f087a   14 months ago   572MB

Since they show in dangling=true, I assume they're dangling, but maybe there's more to the story?

Here's a docker inspect of one of them:

➜  ~ docker inspect 51a86feb574c
[
    {
        "Id": "sha256:51a86feb574c14a3433989fe8f8d1b2036cde019d18e94fc0f6f424a608f6816",
        "RepoTags": [],
        "RepoDigests": [
            "moodlehq/moodle-php-apache@sha256:a90e0f615edc051d3a0dde0e82fa3963a64cabf68c24c0c161a7d502d9a0fcbe"
        ],
        "Parent": "",
        "Comment": "buildkit.dockerfile.v0",
        "Created": "2022-11-27T13:14:34.466460837Z",
        "Container": "",
        "ContainerConfig": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": null,
            "Cmd": null,
            "Image": "",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": null
        },
        "DockerVersion": "",
        "Author": "",
        "Config": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "PHPIZE_DEPS=autoconf \t\tdpkg-dev \t\tfile \t\tg++ \t\tgcc \t\tlibc-dev \t\tmake \t\tpkg-config \t\tre2c",
                "PHP_INI_DIR=/usr/local/etc/php",
                "APACHE_CONFDIR=/etc/apache2",
                "APACHE_ENVVARS=/etc/apache2/envvars",
                "PHP_CFLAGS=-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64",
                "PHP_CPPFLAGS=-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64",
                "PHP_LDFLAGS=-Wl,-O1 -pie",
                "GPG_KEYS=39B641343D8C104B2B146DC3F9C39DC0B9698544 E60913E4DF209907D8E30D96659A97C9CF2A795A 1198C0117593497A5EC5C199286AF1F9897469DC",
                "PHP_VERSION=8.2.0RC6",
                "PHP_URL=https://downloads.php.net/~sergey/php-8.2.0RC6.tar.xz",
                "PHP_ASC_URL=https://downloads.php.net/~sergey/php-8.2.0RC6.tar.xz.asc",
                "PHP_SHA256=b1b4fcb08c257b73ae817c6a2d93b78ca5e5ace42c5f5887ed6447f06fa7bfc6",
                "TARGETPLATFORM=linux/arm64",
                "LD_LIBRARY_PATH=/usr/local/instantclient"
            ],
            "Cmd": [
                "apache2-foreground"
            ],
            "Image": "",
            "Volumes": null,
            "WorkingDir": "/var/www/html",
            "Entrypoint": [
                "docker-php-entrypoint"
            ],
            "OnBuild": null,
            "Labels": null,
            "StopSignal": "SIGWINCH"
        },
        "Architecture": "arm64",
        "Os": "linux",
        "Size": 586475265,
        "VirtualSize": 586475265,
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/444fe26f62e175c43088a70be2349ff6d36964690a10c67c119c5d6a16c338d2/diff:/var/lib/docker/overlay2/05eafc56f03ca7b5566ad7b1a9ab52ad41deb6378ff619f249f6071996ae2cba/diff:/var/lib/docker/overlay2/6627b9118f0833ef7bac4ebfabba80d3f4cc855bb98bcb4572f93b16d798f3df/diff:/var/lib/docker/overlay2/467ad9397a5c9786e0eaaef9232265fc2f7f8cb6b4ee7f7610e79e92671d4fbb/diff:/var/lib/docker/overlay2/e20b7d97698a00ed7876f068b4264cdd583b20dc31701e8e48bdfeabbced0ff9/diff:/var/lib/docker/overlay2/d525abf93a5943638273f39459f62c4068a42343612c4364499b5ec45c17b58e/diff:/var/lib/docker/overlay2/9873b6e21ce8d4b9e3c407e66658e629f971b4d295a0de78f2c9fd988d57ebba/diff:/var/lib/docker/overlay2/90c3cbcb3c19168ef13c490508031dced32243a2240ee602cfe619a5470bcd84/diff:/var/lib/docker/overlay2/7fa7ae2d01baaede39ac6a2fff60303cefc264aa440c23990062f1823e7ab44c/diff:/var/lib/docker/overlay2/7ace388e019983762d07364e331ce20995b684b71d3ffe51bb9965d6021edb1a/diff:/var/lib/docker/overlay2/dd746f350ad133fddfcb6badecebdff4e4cfd62dc459e448a238d6ca7169d659/diff:/var/lib/docker/overlay2/48b00f85c7fe6a99229c8c7ef5c99ae5593494db814ec7dfa55699fcedee2872/diff:/var/lib/docker/overlay2/8b3452318418ccdc3508b9deab147402b91f7d9e1f488f5799108597d8af5966/diff:/var/lib/docker/overlay2/c6a1d961cb09d55d4b530676dac0193bbadae5da8aeba06f685e29e0b1faf5d0/diff:/var/lib/docker/overlay2/dd4a60ff23a9fd3393588a89cee315b7c0f56a15d8bb44ceb866233a86faf88d/diff:/var/lib/docker/overlay2/dd17b3762ad686f6762d3f355583f2350c8dab5cdbaa278eff75e291773a3ebc/diff:/var/lib/docker/overlay2/0a5d0041fb477a81ddc475b68ef4b6faeb279977950f2b3af83fafeb8c55982c/diff:/var/lib/docker/overlay2/d2f8e95dc8882decb559025c85816410f9a442772001fea799c47dd47c9447b0/diff:/var/lib/docker/overlay2/12dae78dd07691395aeb409787a07d8cc639782865df4fdd5f1396b4fcf2d2c2/diff",
                "MergedDir": "/var/lib/docker/overlay2/4097a37b63e2c3b290b280a7b2159001f9d42cd11fc39b5833f4e38943083476/merged",
                "UpperDir": "/var/lib/docker/overlay2/4097a37b63e2c3b290b280a7b2159001f9d42cd11fc39b5833f4e38943083476/diff",
                "WorkDir": "/var/lib/docker/overlay2/4097a37b63e2c3b290b280a7b2159001f9d42cd11fc39b5833f4e38943083476/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:acef1b1c001e7f34ee6701a5bec3c73c5f0661ecdb6415b295a9aa426a5fdec0",
                "sha256:323963f5801b3184d4a922984ee5eb35b345b509bb13cd3f95755e415e1a89f6",
                "sha256:4a9b2f3b684b1bc2782c44de8bd4028007026207783790d423da2eee4b8e2650",
                "sha256:4aad40cd409b20ce4d52f934ce62d558484c014650527debd948cc3f91e48de6",
                "sha256:b2f3add5bb27034f479658190da3620e331cb346495f17156cac804b8ae1d051",
                "sha256:90867d0da86a91f07773d8775fce622b5307b9f5f10022b85e6385205344e901",
                "sha256:952c73c7ad3ca14dad3c26eb9bcd7b01f4632da305b6b0786c1122b6dffdf183",
                "sha256:8107f1cc6982995932a7a73af3e4a8fc05747a12fce12ca2e971aee355c1bc9c",
                "sha256:70ade456cd19647ff46e3ad6be3fc5a2db57df5c1faf90f57768a7b0e987be73",
                "sha256:893cd05ed220aad5976b6ec8e6a9c225285809b6530f39ad7fcb13c7f474fa73",
                "sha256:1e82b3b573ebf0201cf5abba4082196a0f36153e924b7ff10c18a5a7bface8d7",
                "sha256:0c2dc37d6637ee46ad4ce65eb8610b374bd0976492654c363ab153ba8f60a542",
                "sha256:8700ceaca3fbae5e7cf5b9ed5bbac38438da5cb8ca0c192b3818b54a3852550f",
                "sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef",
                "sha256:a837bbd18431cd78325f090938c236c7cc4e1214bdb4ac967a28b355dfdb71f9",
                "sha256:bd68401ad43bb1fec6c0e06fe54ea9cab31537ea28f9201b4504493a3de66564",
                "sha256:2ca25b1ef3649062f2262603a96e27fcac3aa3d284039d4bff3e2770a98c1b46",
                "sha256:6b7d5deeb9bbdf500ee3a13a3caf66c966d846cbfb16e16f17769952c61a2bfe",
                "sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef",
                "sha256:f12382b8263a2e709497b27bd2ccfb7ac49eb08265feff8a0f0b8b6393c06b64"
            ]
        },
        "Metadata": {
            "LastTagTime": "0001-01-01T00:00:00Z"
        }
    }
]