dockeralpine-linuxalpine-package-keeper

Remove package that were installed as dependancies by apk


I'm looking for an equivalent to apt autoremove

I've seen stated everywhere online that it's not required because apk does it automatically when doing apk del. But it's very easy to verify that it doesn't actually does that:

docker run --entrypoint "/bin/sh" -it python:3.9-alpine
# apk add gcc
.......
OK: 117 MiB in 46 packages

# apk del gcc
....
OK: 14 MiB in 36 packages

You can also run apk list before and after to convince yourself of all the packages that were not removed

as you can see there are 113 MB worth of packages that were not removed (apk list shows hundreds of packages here), I really want to get rid of everything that was installed.

How can I do that ? Is that a bug, should everything be removed ? What can I do ?


Solution

  • I asked myself the same question, so to verify I did some tests:

    1. Mesure the disk usage inside the docker
    2. Install multiple packages with their own dependencies
    3. Mesure the disk usage inside the docker
    4. Uninstall the same packages
    5. Mesure the disk usage inside the docker

    What you get is that:

    1. Even though apk add says it downloads 200MiB (arbitrary value for the example), it might actually only install an additional 160MiB.
    2. Once you mesure the disk usage after install, it did increase (not really surprising).
    3. Even though apk del says it uninstalled 20MiB (arbitrary value for the example), it does indeed remove the other 160MiB, which mean that apk del is indeed doing its work properly.

    The reason why the image is suddenly growing in size is because docker is doing some caching steps in-between. If possible, try to do the install and uninstall in a single RUN command.