Supervisor deleting homeassistant docker image on start up

Hi,

I have a home assistant supervised installed in a raspberry pi 3 over Debian 12 with docker 26.0. It works great. My only issue is when I reboot, it takes almost half an hour to be available again. After doing some research I have found out that by some reason that I do not unsertand, the supervisor is deleting the home assistant docker image and redownloading it in every restart. I mean, the image is there when the pi is starting:

ghcr. io/home-assistant/raspberrypi3-homeassistant 2024.7.2 a892826a2136 8 days ago 1.45GB

But after a minute in the reboot, the image disappears. This is shown in the log

2024-07-18 23:37:26.355 INFO (MainThread) [supervisor.homeassistant.secrets] Loaded 2 Home Assistant secrets
2024-07-18 23:37:26.371 INFO (MainThread) [supervisor.docker.interface] Attaching to ghcr. io/home-assistant/raspberrypi3-homeassistant with version 2024.7.2
2024-07-18 23:37:26.415 INFO (SyncWorker_1) [supervisor.docker.manager] Cleaning homeassistant application
2024-07-18 23:37:28.891 INFO (SyncWorker_0) [supervisor.docker.manager] Removing image ghcr. io/home-assistant/raspberrypi3-homeassistant with latest
2024-07-18 23:37:28.904 INFO (SyncWorker_0) [supervisor.docker.manager] Removing image ghcr. io/home-assistant/raspberrypi3-homeassistant with 2024.7.2
2024-07-18 23:38:30.557 INFO (MainThread) [supervisor.docker.interface] Downloading docker image ghcr. io/home-assistant/raspberrypi3-homeassistant with tag 2024.7.2.

And then it takes more or less 20 minutes in download and prepare this image. When this is over, homeassistant is available again.

My question is, anyone has any idea why the supervisor is deleting this image everytime my system restarts?

I have the same problem, you can see from the following log that it takes around 7 minutes every time to download the same image again (note the last 2 timestamps):

2024-08-06 16:09:51.255 INFO (MainThread) [supervisor.homeassistant.secrets] Loaded 1 Home Assistant secrets
2024-08-06 16:09:51.341 INFO (MainThread) [supervisor.docker.interface] Attaching to ghcr.io/home-assistant/raspberrypi3-homeassistant with version 2024.7.4
2024-08-06 16:09:51.380 INFO (SyncWorker_1) [supervisor.docker.manager] Cleaning homeassistant application
2024-08-06 16:09:52.930 INFO (SyncWorker_0) [supervisor.docker.manager] Removing image ghcr.io/home-assistant/raspberrypi3-homeassistant with latest
2024-08-06 16:09:52.944 INFO (SyncWorker_0) [supervisor.docker.manager] Removing image ghcr.io/home-assistant/raspberrypi3-homeassistant with 2024.7.4
2024-08-06 16:10:31.192 INFO (MainThread) [supervisor.docker.interface] Downloading docker image ghcr.io/home-assistant/raspberrypi3-homeassistant with tag 2024.7.4.
2024-08-06 16:17:12.200 INFO (MainThread) [supervisor.os.manager] No Home Assistant Operating System found

So I’d like to understand the reason for this behavior.
In the meantime I found a workaround: simply tag the current Core image, so that, when the Supervisor deletes the images, Docker keeps the actual files since there is the new tag “protecting” the image.

For example I did:

docker tag ghcr.io/home-assistant/raspberrypi3-homeassistant:2024.7.4 roby/homeassistant:protected

and, rebooting the system, the Supervisor deletes the tags it knows, but the image remains on the disk, since it has the new tag.
So, when it tries to download the image again, it immediately founds the existing image and proceeds (note the last 2 timestamps):

2024-08-06 16:27:51.684 INFO (MainThread) [supervisor.homeassistant.secrets] Loaded 1 Home Assistant secrets
2024-08-06 16:27:51.753 INFO (MainThread) [supervisor.docker.interface] Attaching to ghcr.io/home-assistant/raspberrypi3-homeassistant with version 2024.7.4
2024-08-06 16:27:51.810 INFO (SyncWorker_1) [supervisor.docker.manager] Cleaning homeassistant application
2024-08-06 16:27:53.390 INFO (SyncWorker_0) [supervisor.docker.manager] Removing image ghcr.io/home-assistant/raspberrypi3-homeassistant with latest
2024-08-06 16:27:53.402 INFO (SyncWorker_0) [supervisor.docker.manager] Removing image ghcr.io/home-assistant/raspberrypi3-homeassistant with 2024.7.4
2024-08-06 16:27:53.525 INFO (MainThread) [supervisor.docker.interface] Downloading docker image ghcr.io/home-assistant/raspberrypi3-homeassistant with tag 2024.7.4.
2024-08-06 16:27:54.747 INFO (MainThread) [supervisor.os.manager] No Home Assistant Operating System found

Of course the downside of this approach is that when there will be a new version of the Core you will have to delete your tag (which will be keeping a useless old image on the disk) and do it again for the new version.

For anybody interested, I just created a simple bash script (scheduled to run every hour) to ensure the “protected” tag exists:

#!/bin/bash

# Name of the image to check
TARGET_IMAGE="local/homeassistant:protected"

# Name of the source image
SOURCE_IMAGE="ghcr.io/home-assistant/raspberrypi3-homeassistant"

# Check if the target image already exists
if docker image inspect "$TARGET_IMAGE" > /dev/null 2>&1; then
    echo "The image '$TARGET_IMAGE' already exists. Exiting."
    exit 0
fi

# Find the most recent image of 'ghcr.io/home-assistant/raspberrypi3-homeassistant'
LATEST_IMAGE=$(docker images --format "{{.Repository}}:{{.Tag}}" --filter=reference="$SOURCE_IMAGE:*" | sort -r | head -n 1)

# Check if an image was found
if [ -z "$LATEST_IMAGE" ]; then
    echo "No image found for '$SOURCE_IMAGE'. Exiting."
    exit 1
fi

# Create the 'local/homeassistant:protected' tag pointing to the most recent image found
docker tag "$LATEST_IMAGE" "$TARGET_IMAGE"

echo "Tag '$TARGET_IMAGE' created pointing to '$LATEST_IMAGE'."