How to use docker images filter

后端 未结 7 730
耶瑟儿~
耶瑟儿~ 2020-12-08 12:50

I can write

docker images --filter \"dangling=true\"

What other filters can I use?

I can use something like this?

         


        
相关标签:
7条回答
  • 2020-12-08 13:12

    FYI, without filter, but for delete all images when you use as testing or learning,

    docker image rm -f $(docker image ls)

    Greetings.

    0 讨论(0)
  • 2020-12-08 13:16

    There's another example, works with version 17.09++:

    sudo docker rmi $(sudo docker images -f=reference="registry.gitlab.com/example-app" -f "dangling=true" -q)
    

    Explanation:

    • reference - we are referencing images by repository name;
    • dangling=true - we are removing untagged images;
    • -q - means quiet, showing only numeric IDs of images, instead of a whole line.

    This command removes all images that have a repository name "registry.gitlab.com/example-app" and untagged (have <none> in a tag column)

    Reference link: https://docs.docker.com/engine/reference/commandline/images/#filtering

    0 讨论(0)
  • 2020-12-08 13:17

    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

    • docker images filtering
    • docker docs
    0 讨论(0)
  • 2020-12-08 13:20

    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.

    0 讨论(0)
  • 2020-12-08 13:20

    In Docker v1.7:

    The currently supported filters are:

    • dangling (boolean - true or false)
    • label (label=<key> or label=<key>=<value>)
    0 讨论(0)
  • 2020-12-08 13:20

    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

    0 讨论(0)
提交回复
热议问题