How to use docker images filter

2019-02-03 21:47发布

I can write

docker images --filter "dangling=true"

What other filters can I use?

I can use something like this?

docker images --filter "running=false"

标签: docker
5条回答
The star\"
2楼-- · 2019-02-03 22:03

Docker v1.13.0 supports the following conditions:

  -f, --filter value    Filter output based on conditions provided (default [])
                        - dangling=(true|false)
                        - label=<key> or label=<key>=<value>
                        - before=(<image-name>[:tag]|<image-id>|<image@digest>)
                        - since=(<image-name>[:tag]|<image-id>|<image@digest>)
                        - reference=(pattern of an image reference)

Or use grep to filter images by some value:

$ docker images | grep somevalue

References

查看更多
姐就是有狂的资本
3楼-- · 2019-02-03 22:14

You can also use the REPOSITORY argument to docker images to filter the images.

For example, suppose we have the images:

$ docker images
REPOSITORY           TAG          IMAGE ID         CREATED         SIZE
local-foo            latest       17864104b328     2 months ago    100 MB
example.com/bar      latest       b94c37de2801     9 months ago    285 MB
example.com/baz      latest       a004e3ac682c     2 years ago     221 MB

We can explicitly filter for all images with a given name:

$ docker images example.com/bar
REPOSITORY           TAG          IMAGE ID         CREATED         SIZE
example.com/bar      latest       b94c37de2801     9 months ago    285 MB

Docker also supports globbing:

$ docker images "example.com/*"
REPOSITORY           TAG          IMAGE ID         CREATED         SIZE
example.com/bar      latest       b94c37de2801     9 months ago    285 MB
example.com/baz      latest       a004e3ac682c     2 years ago     221 MB

Official docs here.

查看更多
别忘想泡老子
4楼-- · 2019-02-03 22:25

sudo docker images --filter "running=false"

For cleaning up old stopped containers you can use:
docker container prune

To remove untagged images you can use:
docker image prune

查看更多
▲ chillily
5楼-- · 2019-02-03 22:27

In Docker v1.7:

The currently supported filters are:

  • dangling (boolean - true or false)
  • label (label=<key> or label=<key>=<value>)
查看更多
对你真心纯属浪费
6楼-- · 2019-02-03 22:28

For me,

docker images -q | while read IMAGE_ID; do
    docker inspect --format='{{.Created}}' --type=image ${IMAGE_ID}
done

did the trick. The date command is able to produce output in the same format via

date -Ins --date='10 weeks ago'

which allows me to compare timestamps. I still use the filter for dangling images for convenience, though.

查看更多
登录 后发表回答