Skip to content

Instantly share code, notes, and snippets.

@marvell
Created May 18, 2015 15:29
Show Gist options
  • Select an option

  • Save marvell/7c812736565928e602c4 to your computer and use it in GitHub Desktop.

Select an option

Save marvell/7c812736565928e602c4 to your computer and use it in GitHub Desktop.
Remove APT cache (for Dockerfile)
apt-get clean autoclean
apt-get autoremove --yes
rm -rf /var/lib/{apt,dpkg,cache,log}/
@ylhyh
Copy link

ylhyh commented Dec 31, 2025

Executing rm -rf /var/lib/{apt,dpkg,cache,log}/ will corrupt the apt environment and cause the following error:

Error: Could not open lock file /var/lib/dpkg/lock-frontend - open (2: No such file or directory)
Error: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?

@jsnfwlr
Copy link

jsnfwlr commented Jan 3, 2026

Executing rm -rf /var/lib/{apt,dpkg,cache,log}/ will corrupt the apt environment and cause the following error:

Error: Could not open lock file /var/lib/dpkg/lock-frontend - open (2: No such file or directory)
Error: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?

Well yes, these commands should be the last RUN ditective given in the Dockerfile in order to reduce the size of it.

If you need to use apt from within the container later for any reason you can try rm -rf /var/lib/{apt,dpkg,cache,log}/* instead. This will keep the folders but remove their contents.

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