# How to delete cache?

**URL:** <https://forums.docker.com/t/how-to-delete-cache/5753>\
**Category:** General\
**Created:** [January 20, 2016, 11:19pm UTC](https://forums.docker.com/t/how-to-delete-cache/5753 "2016-01-20T23:19:04Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![irfuel](https://avatars.discourse-cdn.com/v4/letter/i/d07c76/32.png) [@irfuel](https://forums.docker.com/u/irfuel)\
**Post date:** [January 20, 2016, 11:19pm UTC](https://forums.docker.com/t/how-to-delete-cache/5753/1 "2016-01-20T23:19:04Z")

</div>

Is there a way to delete the Docker cache?

---

<div class="post-metadata">

**Author:** ![andyneff](https://avatars.discourse-cdn.com/v4/letter/a/a9adbd/32.png) [@andyneff](https://forums.docker.com/u/andyneff)\
**Post date:** [January 21, 2016, 2:31pm UTC](https://forums.docker.com/t/how-to-delete-cache/5753/2 "2016-01-21T14:31:30Z")

</div>

Last time I checked, there wasn’t a specific docker command for this

I use a few useful alias

```
alias docker_clean_images='docker rmi $(docker images -a --filter=dangling=true -q)'
alias docker_clean_ps='docker rm $(docker ps --filter=status=exited --filter=status=created -q)'

```

The first one cleans all dangling images. This is useful for removing intermediate images left over from multiple builds. The second one is for removing stopped containers. These are aliases I use for routine maintenance

If you want to remove ALL of your cache, you first have to make sure all containers are stopped and removed, since you cannot remove an image in use by a container. So something similar

```
docker kill $(docker ps -q)
docker_clean_ps
docker rmi $(docker images -a -q)

```

This would kill and remove all images in your cache. Less recommended, you could wipe the /var/lib/docker dir and start docker over, but that’s hardly necessary just to clear the cache

---

<div class="post-metadata">

**Author:** ![otiai10](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/otiai10/32/17668_2.png) [@otiai10](https://forums.docker.com/u/otiai10)\
**Post date:** [November 30, 2017, 12:28pm UTC](https://forums.docker.com/t/how-to-delete-cache/5753/3 "2017-11-30T12:28:17Z")

</div>

```auto
docker system prune -a

```

wish it works

---

<div class="post-metadata">

**Author:** ![ramizrshaik](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@ramizrshaik](https://forums.docker.com/u/ramizrshaik)\
**Post date:** [June 14, 2018, 5:20pm UTC](https://forums.docker.com/t/how-to-delete-cache/5753/4 "2018-06-14T17:20:56Z")

</div>

This will delete everything not only cached intermittent images layers but also, images that aren’t connected to at least one container and all exited containers.

is there any command to delete only cached image layers?

---

<div class="post-metadata">

**Author:** ![im7mortal](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/im7mortal/32/20177_2.png) [@im7mortal](https://forums.docker.com/u/im7mortal)\
**Post date:** [June 20, 2018, 9:43pm UTC](https://forums.docker.com/t/how-to-delete-cache/5753/5 "2018-06-20T21:43:58Z")

</div>

I pull git repository in my _production-ready_ image.

```auto
RUN git clone --depth=1 --branch=${BRANCH} ${REPOSITORY} .

```

Before this step I have really heavy steps ( **1 hour of OpenCV coompilation** )  
But if I push some changes to git then I need to add some invalidation step. It’s really messy.

I found good solution to use the **LABEL**. I put a git ref value in the label. It’s even bring real benefits also.  
But(!) I specified the label wrongly at latest build

```auto
LABEL HASH_COMMIT=${HASH_COMMIT}
# instead of 
LABEL "HASH_COMMIT"=${HASH_COMMIT}

```

Docket didn’t set the HASH\_COMMIT to labels. (I check via _docker inspect_)  
**But Docker anyway use cache if I fix it!**

I don’t want to do _docker system prune -a_  
**It will remove different heavy images too!**

I have a lot of pain with it ☹

---

<div class="post-metadata">

**Author:** ![im7mortal](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/im7mortal/32/20177_2.png) [@im7mortal](https://forums.docker.com/u/im7mortal)\
**Post date:** [June 20, 2018, 9:47pm UTC](https://forums.docker.com/t/how-to-delete-cache/5753/6 "2018-06-20T21:47:11Z")

</div>

If you have a heavy cache which you want to save. f.e. **1 hour of OpenCV coompilation**  
or other images which you don’t wanna remove. Then it’s big pain

---

<div class="post-metadata">

**Author:** ![harendra122](https://avatars.discourse-cdn.com/v4/letter/h/e36b37/32.png) [@harendra122](https://forums.docker.com/u/harendra122)\
**Post date:** [July 1, 2019, 12:36pm UTC](https://forums.docker.com/t/how-to-delete-cache/5753/7 "2019-07-01T12:36:28Z")

</div>

```auto
docker builder prune

```

it remove build cache  
for more info [click](https://docs.docker.com/engine/reference/commandline/builder_prune/)

---

<div class="post-metadata">

**Author:** ![christokiwi](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/christokiwi/32/24827_2.png) [@christokiwi](https://forums.docker.com/u/christokiwi)\
**Post date:** [August 27, 2019, 4:09am UTC](https://forums.docker.com/t/how-to-delete-cache/5753/9 "2019-08-27T04:09:10Z")

</div>

@harendra122  
This did the trick for me.

Thankyou

---

<div class="post-metadata">

**Author:** ![waynish](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/waynish/32/32590_2.png) [@waynish](https://forums.docker.com/u/waynish)\
**Post date:** [November 14, 2019, 2:10pm UTC](https://forums.docker.com/t/how-to-delete-cache/5753/10 "2019-11-14T14:10:12Z")

</div>

What’s the strategy for leaning up old images? If you’ve been running docker-compose build without --no-cache for a while, then images all the way back are based on each other… So I’ll eventually run out of disk space. What’s the method for keeping the last ~15 images when always using “docker-compose build”?  
Thanks!

---

<div class="post-metadata">

**Author:** ![jenikm](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/jenikm/32/25806_2.png) [@jenikm](https://forums.docker.com/u/jenikm)\
**Post date:** [December 4, 2019, 4:29am UTC](https://forums.docker.com/t/how-to-delete-cache/5753/11 "2019-12-04T04:29:05Z")

</div>

Works great, thanks!

---

<div class="post-metadata">

**Author:** ![andresmascl](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/andresmascl/32/35248_2.png) [@andresmascl](https://forums.docker.com/u/andresmascl)\
**Post date:** [July 3, 2022, 12:12am UTC](https://forums.docker.com/t/how-to-delete-cache/5753/13 "2022-07-03T00:12:27Z")

</div>

It works great, thank you very much

---

<div class="post-metadata">

**Author:** ![mikbuch](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/mikbuch/32/39152_2.png) [@mikbuch](https://forums.docker.com/u/mikbuch)\
**Post date:** [February 6, 2023, 5:31pm UTC](https://forums.docker.com/t/how-to-delete-cache/5753/14 "2023-02-06T17:31:54Z")

</div>

The solution suggested by harendra122, of using `docker builder prune` seems to have worked for me. More details here: [docker pull always show "Already exists" for layers during pull even after deleting all images - Stack Overflow](https://stackoverflow.com/a/75364658/8877692)

---

<div class="post-metadata">

**Author:** ![dataheadless](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/dataheadless/32/54828_2.png) [@dataheadless](https://forums.docker.com/u/dataheadless)\
**Post date:** [May 11, 2023, 2:30pm UTC](https://forums.docker.com/t/how-to-delete-cache/5753/15 "2023-05-11T14:30:09Z")

</div>

Following article explains it in details

[How to clear docker cache](https://techkluster.com/docker/questions-docker/how-to-clear-docker-cache/)

---

<div class="post-metadata">

**Author:** ![hempstead](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/hempstead/32/41531_2.png) [@hempstead](https://forums.docker.com/u/hempstead)\
**Post date:** [July 11, 2023, 8:39pm UTC](https://forums.docker.com/t/how-to-delete-cache/5753/16 "2023-07-11T20:39:12Z")

</div>

“docker builder prune” does the trick!

Thank you for saving some of my hair!

---

<div class="post-metadata">

**Author:** ![thunder](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@thunder](https://forums.docker.com/u/thunder)\
**Post date:** [December 2, 2023, 9:04am UTC](https://forums.docker.com/t/how-to-delete-cache/5753/17 "2023-12-02T09:04:19Z")

</div>

I used “docker buildx prune -f” to clear the cache only  
you can also use “docker systemc df” to check space for Images, Containers, Local Volumes, and Build Cache

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/bluepuma77/32/32688_2.png) [@bluepuma77](https://forums.docker.com/u/bluepuma77)\
**Post date:** [December 2, 2023, 2:09pm UTC](https://forums.docker.com/t/how-to-delete-cache/5753/18 "2023-12-02T14:09:51Z")

</div>

Doesn’t work for me on Debian:

> # docker systemc df
> 
> docker: ‘systemc’ is not a docker command.  
> See ‘docker --help’

Update: it’s `docker system df`

---

<div class="post-metadata">

**Author:** ![sbedmstser](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/sbedmstser/32/44064_2.png) [@sbedmstser](https://forums.docker.com/u/sbedmstser)\
**Post date:** [December 12, 2023, 4:35am UTC](https://forums.docker.com/t/how-to-delete-cache/5753/19 "2023-12-12T04:35:57Z")

</div>

Yes thank you for right solution.

---

<div class="post-metadata">

**Author:** ![shailesh332](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/shailesh332/32/44099_2.png) [@shailesh332](https://forums.docker.com/u/shailesh332)\
**Post date:** [March 18, 2024, 9:50am UTC](https://forums.docker.com/t/how-to-delete-cache/5753/20 "2024-03-18T09:50:49Z")

</div>

bro lots of thank you. you saved my job 🤣

---

<div class="post-metadata">

**Author:** ![raman004](https://avatars.discourse-cdn.com/v4/letter/r/73ab20/32.png) [@raman004](https://forums.docker.com/u/raman004)\
**Post date:** [March 18, 2024, 6:21pm UTC](https://forums.docker.com/t/how-to-delete-cache/5753/21 "2024-03-18T18:21:26Z")

</div>

Open the command prompt and enter the command **docker system prune** and then press enter and after this press y for confirmation

---

<div class="post-metadata">

**Author:** ![carlsock](https://avatars.discourse-cdn.com/v4/letter/c/b4bc9f/32.png) [@carlsock](https://forums.docker.com/u/carlsock)\
**Post date:** [July 30, 2024, 12:16pm UTC](https://forums.docker.com/t/how-to-delete-cache/5753/22 "2024-07-30T12:16:11Z")

</div>

I’ve got another way 😉

To delete the docker build cache, you can use this command [mod update: remove spam link]:

```auto
docker builder prune

```

This command will prompt you to confirm the deletion of the cache. If you wanna delete the cache without any prompts, you can use:

```auto
docker builder prune -f

```

For more options and details, check the docker documentation on `builder prune`.
