Skip to content

docker system prune does not remove reclaimable space #1562

Open

Description

@dominikzalewski

Current behaviour

root@acme:~# docker container ls -a
CONTAINER ID   IMAGE                                                       COMMAND                  CREATED      STATUS                PORTS                                                                          NAMES
39900d4aa961   registry.acme.io/core:4.47                            "catalina.sh run"        4 days ago   Up 4 days (healthy)   0.0.0.0:8080->8080/tcp, [::]:8080->8080/tcp                                    core_app.1.trzd1zc12hp6cr7avcvahwrya
21af351e5098   nginx:1.29.2                                                "/docker-entrypoint.…"   4 days ago   Up 4 days             0.0.0.0:80->80/tcp, [::]:80->80/tcp, 0.0.0.0:443->443/tcp, [::]:443->443/tcp   core_proxy.1.s3fp15dvaryq0droxsl3jok7i
27db266adca1   ghcr.io/pellepelster/solidblocks-rds-postgresql:17-v0.4.6   "/rds/bin/run.sh"        4 days ago   Up 4 days             5432/tcp                                                                       core_db.1.f6wddqmo19q77x8xaoonqxy78
root@acme:~# docker image ls
REPOSITORY                                        TAG       IMAGE ID       CREATED        SIZE
registry.acme.io/core                       <none>    40f97602d1eb   5 days ago     607MB
ghcr.io/pellepelster/solidblocks-rds-postgresql   <none>    a4d548f775a6   3 weeks ago    146MB
registry.acme.io/core                       4.29      d6bb381c8b81   5 months ago   593MB
nginx                                             <none>    657fdcd1c365   5 months ago   152MB
root@acme:~# docker system df
TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          4         3         1.499GB   593.4MB (39%)
Containers      3         3         566.6MB   0B (0%)
Local Volumes   5         5         26.73GB   0B (0%)
Build Cache     0         0         0B        0B
root@lagerinn:~# docker system prune -f 
Total reclaimed space: 0B

Expected behaviour

Reclaimable space, ie. image

registry.acme.io/core                       4.29      d6bb381c8b81

is removed.

Activity

  1. m-mahdi-abbaszade commented on Jun 15, 2026

    @m-mahdi-abbaszade

    The reason docker system prune -f isn't removing your old 4.29 image comes down to how Docker handles dangling vs. unused images, combined with a subtle detail hiding in your container names.

    Here is exactly what is happening and how to clean it up.


    The Culprit: "Unused" vs. "Dangling" Images

    By default, docker system prune only removes dangling images.

    • Dangling Image: An image that has no name or tag (it shows up as <none>:<none>). This usually happens when you build or pull a newer version of an image with the exact same tag, leaving the old layers orphaned.
    • Unused Image: An image that has a valid name and tag (like registry.acme.io/core:4.29), but is not actively being used by any container (running or stopped).

    Because your 4.29 image still has its explicit name and tag, Docker considers it "unused," not "dangling." Therefore, a standard prune leaves it untouched to protect you from accidentally deleting an image you intentionally pulled or built.


    The Docker Swarm Factor

    If you look at your docker container ls -a output, your container names look like this:
    core_app.1.trzd1zc12hp6cr7avcvahwrya

    Those long, randomized hashes at the end mean these containers were deployed via Docker Swarm (or a similar orchestrator).

    When Swarm performs a rolling upgrade or service update, it keeps old task definitions and history in its database. Even if a container isn't actively listed as running, Docker Swarm might still hold a hidden reference to that older 4.29 image structure, which locks it down and blocks a standard cleanup.


    How to Force Reclaim the Space

    To force Docker to clean up both dangling and tagged, unused images, you need to append the -a (or --all) flag to your prune command.

    Run this instead:

    docker system prune -a -f
    

    Or, if you only want to target images specifically without touching other cached elements:

    docker image prune -a -f
    

    What if it still won't delete?

    If you run docker image prune -a -f and it still says Total reclaimed space: 0B, it means an existing container (or a hidden Swarm task history) is actively referencing d6bb381c8b81.

    You can break through this by forcing the removal directly via its Image ID:

    docker rmi -f d6bb381c8b81
    

    (Note: If a running container is using it, this will warn you, but if it's just held up by old Swarm history, this will successfully untag and delete the image).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions