Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker_prune: filter "until" seems without effect #591

Closed
fredbcode opened this issue Feb 17, 2023 · 9 comments · Fixed by #593
Closed

docker_prune: filter "until" seems without effect #591

fredbcode opened this issue Feb 17, 2023 · 9 comments · Fixed by #593
Labels
bug Something isn't working docker-plain plain Docker (no swarm, no compose, no stack)

Comments

@fredbcode
Copy link

I discovered the issue when I tried to purge several docker images

- name: Prune containers older than 12 months
  community.docker.docker_prune:
    containers: yes
    networks: yes
    volumes: yes
    containers_filters:
# only consider containers created more than 12 months ago
      until: 8760h 

Old unused images

squid           <none>          cf1252e485f5   13 months ago   270MB
ntpd            <none>          92e81112bcb9   13 months ago   82.7MB
syslog-ng       3.31.2          8c8f5068089e   23 months ago   482MB

Ansible debug

    "changed": false,
    "containers": [],
    "containers_space_reclaimed": 0,
    "invocation": {
        "module_args": {
            "api_version": "auto",
            "builder_cache": false,
            "ca_cert": null,
            "client_cert": null,
            "client_key": null,
            "containers": true,
            "containers_filters": {
                "until": "8760h"
            },
            "debug": false,
            "docker_host": "unix://var/run/docker.sock",
            "images": false,
            "images_filters": null,
            "networks": true,
            "networks_filters": null,
            "ssl_version": null,
            "timeout": 60,
            "tls": false,
            "tls_hostname": null,
            "use_ssh_client": false,
            "validate_certs": false,
            "volumes": true,
            "volumes_filters": null
        }
    },
    "networks": [],
    "volumes": [],
    "volumes_space_reclaimed": 0
}

I tried with 860h without more success, the result is always no change

Version: community.docker 3.4.0

@fredbcode fredbcode changed the title Filter until seems without effect Filter "until" seems without effect Feb 17, 2023
@felixfontein felixfontein added the bug Something isn't working label Feb 17, 2023
@felixfontein
Copy link
Collaborator

From the code it looks like these filters are passed to the Docker daemon. I guess this needs to be debugged in more detail...

@felixfontein felixfontein added the docker-plain plain Docker (no swarm, no compose, no stack) label Feb 17, 2023
@fredbcode
Copy link
Author

For information tested with: Docker version 20.10.5

Manual command works well

docker image prune -a --filter "until=8760h"

deleted: sha256:133152c0450e5b53386d10bc56c3ebc75e5200eebf4a092dababbb29a28b9772
deleted: sha256:6f86de7b9f69b9dc16ab5a2b75dc41181c3a02cabcf3b356dc3ff52a2c4a41d7
deleted: sha256:d875220aad8494cc8863d9e246de6830fe9045a967c10546118bb410a05547d3
deleted: sha256:57e7e9114e97c297a992ea486c5a1258b1d2728196841cbc10b475a75bd73777
deleted: sha256:6678d9219dcc56bbc418d8dd86d76ef46d82c76cc234cec52c32a233be5b8ccc
deleted: sha256:fb812ed56486a452a580a1a0f99b62f5d9923dbbabf5bc564eb7f8ab7afcf799
deleted: sha256:61152d1404d8c239f68203c289b9c7187da202f24ebfe318dd14ca67cec82d89
deleted: sha256:2edcec3590a4ec7f40cf0743c15d78fb39d8326bc029073b41ef9727da6c851f

Total reclaimed space: 272.1MB

@felixfontein
Copy link
Collaborator

Hmm, but in that command you are pruning images, not containers? Your ansible task is pruning containers, but not images.

@felixfontein felixfontein changed the title Filter "until" seems without effect docker_prune: filter "until" seems without effect Feb 17, 2023
@fredbcode
Copy link
Author

Yes sorry, bad copy paste

- name: Prune containers older than 6 months
  community.docker.docker_prune:
    containers: true
    networks: true
    volumes: true
    images: true
    containers_filters:
# only consider containers created more than 6 months ago
# 4320h = 24 hour/day * 30 days/month * 6 months
      until: 4320h 

But I'm wrong, the issue is not related with "until"

- name: Prune
  community.docker.docker_prune:
    networks: true 
    volumes: true
    images: true
    containers: true

Doesn't works -> "No change" in ansible

Unused images

confmi-squid-sanse2g                                         latest          be5973daf09d   16 months ago   514MB
3.31.2          8c8f5068089e   23 months ago   482MB
1.1.7           24a904a08ac5   2 years ago     64.7MB
squid                                                        embarque        c08f0c8909c8   2 years ago     512MB

Another test, create an unused network

docker network create toto

Same no change, but the network is well removed

ok: [] => {
    "changed": false,
    "containers": [],
    "containers_space_reclaimed": 0,
    "images": [],
    "images_space_reclaimed": 0,
    "invocation": {
        "module_args": {
            "api_version": "auto",
            "builder_cache": false,
            "ca_cert": null,
            "client_cert": null,
            "client_key": null,
            "containers": true,
            "containers_filters": null,
            "debug": false,
            "docker_host": "unix://var/run/docker.sock",
            "images": true,
            "images_filters": null,
            "networks": true,
            "networks_filters": null,
            "ssl_version": null,
            "timeout": 60,
            "tls": false,
            "tls_hostname": null,
            "use_ssh_client": false,
            "validate_certs": false,
            "volumes": true,
            "volumes_filters": null
        }
    },
    "networks": [
        "toto"
    ],
    "volumes": [],
    "volumes_space_reclaimed": 0
}

Maybe I missed something ?

@felixfontein
Copy link
Collaborator

Actually the module always returns changed=false (and it always did that). That's definitely wrong.

@felixfontein
Copy link
Collaborator

#593 should fix this.

@fredbcode
Copy link
Author

Still my images aren't removed, with until or not

It works with "network"

@felixfontein
Copy link
Collaborator

felixfontein commented Feb 24, 2023

Were your images untagged, or did you provide the dangling: false filter?

@fredbcode
Copy link
Author

Sorry for the delay

Yes your are right about dangling, thank you, and with #593 all works well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working docker-plain plain Docker (no swarm, no compose, no stack)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants