Uncloud Image Pruning
Currently uc doesn’t have a prune subcommand to prune images, and even if it had it would still be a
manual operation. It would be better to automate this. This post shows how.
First create an image with this Dockerfile:
FROM --platform=$BUILDPLATFORM alpine:latest
RUN apk add curl
RUN <<EOF
echo \
'#/bin/bash
if ! [[ -S /var/run/docker.sock ]]; then
echo "Docker socket /var/run/docker.sock not found" >&2
exit 1
fi
curl -s -X POST --unix-socket /var/run/docker.sock http://localhost/images/prune
while true; do
sleep 24h
curl -s -X POST --unix-socket /var/run/docker.sock http://localhost/images/prune
done
' > /prune
EOF
RUN chmod +x /prune
WORKDIR /
CMD "/prune"
Build and push that image to a registry and then use this Uncloud compose.yaml to deploy:
# This compose file runs prune.
services:
prune:
image: registry.science.ru.nl/cncz/sys/image/prune:v0.1.23
deploy:
mode: global
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
And deploy with uc deploy, using uc logs prune would show something like:
May 14 21:50:37.218 machine-lyrk prune/92c48 {"ImagesDeleted":[{"Untagged":"sha256:3eeef1a73d9983d324a9a4ee718e21f2bdcc18e9464c86ae531f4494164b3597"},{"Deleted":"sha256:3eeef1a73d9983d324a9a4ee718e21f2bdcc18e9464c86ae531f4494164b3597"},{"Untagged":"sha256:8b7a5ef9a39f4978ef718a019369ba7e57a266f90dd1523188737edeb4936c6d"},{"Deleted":"sha256:8b7a5ef9a39f4978ef718a019369ba7e57a266f90dd1523188737edeb4936c6d"},{"Untagged":"sha256:cf14986f17d07109fe567e4a6fcd125c3c178bf323f3b95e0ba0f08f9eb003cf"},{"Deleted":"sha256:cf14986f17d07109fe567e4a6fcd125c3c178bf323f3b95e0ba0f08f9eb003cf"}],"SpaceReclaimed":47747124}
May 14 21:50:44.454 machine-vkre prune/3ef05 {"ImagesDeleted":[{"Untagged":"sha256:384698426431f40bdb770f8bb93b20053cd3abfa8b7e93737adeeb8f084a581a"},{"Deleted":"sha256:384698426431f40bdb770f8bb93b20053cd3abfa8b7e93737adeeb8f084a581a"}],"SpaceReclaimed":94164362}
Read other posts