Managing images
An image is pulled the first time an instance needs it, and kept. This guide covers pulling ahead of time, private registries, updating what a tag means, and getting the disk space back. See Images for what an image becomes on the host.
Pull ahead of time
A start that needs an image it does not have pulls it first, which can take a while for a large image. Pull it beforehand to make starts quick:
$ dicer pull postgres:17
A pull resolves the reference to a digest, downloads the layers the host does not already have, and converts the image to a disk. Pulling an image the host already has, at the same digest, only asks the registry.
Images are pulled for the host’s architecture: linux/amd64 on an x86_64
host, linux/arm64 on an aarch64 one. An image with no build for it cannot
be pulled.
See what is held
$ dicer images -c name,size,created,"last used"
NAME SIZE CREATED LAST USED
docker.io/library/postgres:17 151 MiB 2 days ago 2 minutes ago
docker.io/library/nginx:1.27 71.2 MiB 3 weeks ago 3 weeks ago
Names are shown in full, with the registry. CREATED is when the image was
pulled to this host. LAST USED is when garbage collection
last found it in use; while that is off, it stays at the pull. The
DIGEST column, left out above, tells apart images pulled under the same
name. dicer info shows how full the disk holding them is.
Private registries
The daemon logs in to a registry with the credentials its
configuration gives for it, under
registries, keyed by the registry’s host as an image’s name gives it:
docker.io, ghcr.io, or registry.example.com:5000. A registry not listed
there is pulled from anonymously.
registries:
docker.io:
username: dicer-bot
password_file: /etc/dicerd/secrets/docker-token
ghcr.io:
username: dicer-bot
password_file: /etc/dicerd/secrets/ghcr-token
123456789012.dkr.ecr.eu-west-1.amazonaws.com:
credential_helper: ecr-loginA registry takes a username and either a password, or a password_file
that holds it; prefer the file, readable only by root, so the secret is not in
the configuration. The file is read at every pull, so a rotated password needs
no restart. A registry whose credentials expire, such as Amazon ECR, takes a
credential_helper instead: the name of a docker-credential-<name> program
on the daemon’s PATH, which gives fresh credentials each time, using root’s
credentials for the cloud, such as an instance role.
Update to a newer image
A tag such as nginx:1.27 or latest means the image most recently pulled
under it on this host. Starting an instance never asks the registry
whether the tag has moved; pulling does:
$ dicer pull nginx:1.27 # the tag now means the new image
$ dicer restart web # web boots from it
$ dicer image prune # the old one is no longer in use
Each image is kept by digest, so after the pull both are listed under the same name until the old one is removed. An instance keeps the image it booted from until it next starts.
To pin an instance to one image, whatever the tag does, give a digest:
$ dicer run -d --name web nginx:1.27@sha256:9d6b58feebd2…
Remove images
An image is in use while an instance is defined to boot from it, a
running guest booted from it, or a snapshot needs it. dicer image prune
deletes every image not in use, with the layers only they needed:
$ dicer image prune
dicer rmi deletes named images. Given a tag, it deletes the image most
recently pulled under it; given a digest, that one. An image in use is
refused, unless with --force: an instance defined to boot from it pulls it
again at its next start, and one running from it keeps running.
$ dicer rmi nginx:1.27
$ dicer rmi --force nginx@sha256:9d6b58feebd2…
Reclaim space automatically
The daemon can remove images it no longer needs by itself. Set either limit, or both, in its configuration:
images:
gc_max_unused_age: 168h # remove images unused for a week
gc_max_size: 50GiB # remove the least recently used while the store is larger
gc_interval: 1h # how often to checkThen restart the daemon, which leaves running guests alone:
$ sudo systemctl restart dicerd
Only images not in use are removed, and none used in the last ten minutes, so an image pulled for an instance about to be created is safe. The size limit counts the image disks and the layer cache together. Each image removed is an event:
$ dicer events --kind image