Score:0

What is the difference between these package cache clearing methods?

id flag

When building Docker images using ubuntu, some devs recommend removing package caches to reduce the size of the generated image by running the following command:

rm -rf /var/lib/apt/lists/*

However, there is also the command apt-get clean which removes the package cache located at /var/cache/apt/archives (reference: https://help.ubuntu.com/community/AptGet/Howto)

Why do devs recommend the former command over the latter? Is there anything to gain by running both commands since they target different cache locations?

id flag
@user535733, sure, here are some https://gist.github.com/marvell/7c812736565928e602c4#gistcomment-2965615 https://stackoverflow.com/questions/61990329/dockerfile-benefits-of-repeated-apt-cache-cleans
user535733 avatar
cn flag
Your [first link](https://gist.github.com/marvell/7c812736565928e602c4#gistcomment-2965615) clearly explains their purpose of deleting the list files. Your [second link](https://stackoverflow.com/questions/61990329/dockerfile-benefits-of-repeated-apt-cache-cleans) seems to be *exactly* the question you are asking, and it is well answered and discussed. Are you saying that you did not understand that correct answer or the discussion? Or are you hoping for some other answer?
id flag
@user535733 I found these example links _after_ I posted my question simply as an evidence to your comment of never seeing devs recommend this, a comment you have deleted. I have been following the practice of using the `rm -rf` command I posted and was simply wondering why this was recommended as I recently came across the `apt-get clean` command. I didn't have the exact links/videos I had seen previously where this was recommended which was a over a two years ago now.
Score:2
mx flag

They do different things. rm -rf /var/lib/apt/lists/* removes package lists, loaded by apt update. apt clean removes cached packages, loaded by apt install or apt upgrade. Both require root permissions (sudo).

id flag
Based on this explanation, there is then merit in performing both if the primary issue is to reduce a docker images size as much as possible.
pasman pasmański avatar
mx flag
Yes, better is to do both.
Score:2
ng flag

The rm command would require sudo. So a simple typo or hitting Enter prematurely would irreparably destroy your system. There is absolutely no reason not to use sudo apt clean for this purpose.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.