Docker-alpine: 'apk cache clean' returns "ERROR: Package cache is not enabled." even though I can see /var/cache/apk/* cache content

Created on 27 Oct 2016  路  7Comments  路  Source: gliderlabs/docker-alpine

Something that's been bothering me for a while is

docker run -ti alpine:latest sh

/ # apk update
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz
v3.4.5 [http://dl-cdn.alpinelinux.org/alpine/v3.4/main]
v3.4.4-21-g75fc217 [http://dl-cdn.alpinelinux.org/alpine/v3.4/community]
OK: 5973 distinct packages available

/ # apk cache clean
ERROR: Package cache is not enabled.

/ # ls -lh /var/cache/apk/*
-rw-r--r--    1 root     root      659.0K Oct 25 20:43 /var/cache/apk/APKINDEX.167438ca.tar.gz
-rw-r--r--    1 root     root       87.9K Oct 19 10:23 /var/cache/apk/APKINDEX.a2e6dac0.tar.gz

This error looks like a bug to me considering the cache is clearly stored under /var/cache/apk, surely it should remove those files?

I can workaround it by avoiding apk update and using --no-cache with search and add commands or manually rm -fr /var/cache/apk/* but the behaviour of apk cache clean seems broken.

question

Most helpful comment

I have actually been using the --no-cache option in many of my builds, but in some cases it's easier to apk update and then run a series of install commands and then I rm -rf /var/cache/apk/* at the end. These are fine workarounds, but I still feel like this is out of alignment with intuitive behaviour and popular tools like yum clean all.

All 7 comments

I don't think those files are part of the cache. According to the documentation at https://wiki.alpinelinux.org/wiki/Local_APK_cache, the cache sub-command is something else and is for keeping a local package cache available. It isn't enabled by default (per the error message).

Ah, in that case perhaps there is (or should be?) another command to clear out the package index data? This is primarily for cleaning up while building docker images.

Also as this is not quit intuitive, perhaps cache clean should be package-cache clean instead and cache clean should do as expected and remove everything under /var/cache/apk and /etc/apk/cache?

What about the --no-cache option? This option will not save indexes when downloading packages:

/ # ls -al /var/cache/apk/
total 8
drwxr-xr-x    2 root     root          4096 Oct 18 18:58 .
drwxr-xr-x    4 root     root          4096 Oct 18 18:58 ..
/ # apk add --no-cache curl
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz
(1/4) Installing ca-certificates (20160104-r4)
(2/4) Installing libssh2 (1.7.0-r0)
(3/4) Installing libcurl (7.50.3-r0)
(4/4) Installing curl (7.50.3-r0)
Executing busybox-1.24.2-r11.trigger
Executing ca-certificates-20160104-r4.trigger
OK: 6 MiB in 15 packages
/ # ls -al /var/cache/apk/
total 8
drwxr-xr-x    2 root     root          4096 Oct 18 18:58 .
drwxr-xr-x    5 root     root          4096 Nov  2 17:05 ..
/ #

Alternatively, rm -f /var/cache/apk/* isn't much longer than apk clean cache.

I have actually been using the --no-cache option in many of my builds, but in some cases it's easier to apk update and then run a series of install commands and then I rm -rf /var/cache/apk/* at the end. These are fine workarounds, but I still feel like this is out of alignment with intuitive behaviour and popular tools like yum clean all.

I understand. But this would be more an upstream general request of Alpine Linux versus this repository or using the image. Would you agree?

If so, I'd bring this up in the Alpine Linux IRC channel or their user mailing list.

Yes agreed, closing.

Thanks for the feedback on this, much appreciated.

Sorry to dig up an old thread...

According to Alpine's Local APK cache, you should create the cache with setup-apkcache. Then you can maintain it or clean it over time.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dniku picture dniku  路  4Comments

robinmonjo picture robinmonjo  路  4Comments

gliptak picture gliptak  路  4Comments

dinogun picture dinogun  路  3Comments

kalaksi picture kalaksi  路  3Comments