Skip to content
This is the documentation for v0.3. Read the latest.
Managing images

Managing images

An image is pulled when an instance is created from it, and kept. This guide covers pulling ahead of time, choosing when images are pulled, 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

Creating an instance from an image the host does not have pulls it first, which can take a while for a large image. Pull it beforehand to make creating instances 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.

Choose when an image is pulled

--pull on dicer run, dicer create and dicer compose up says when the image is pulled, as with docker run --pull:

$ dicer run -d --pull always nginx:1.27    # follow the tag if it has moved
$ dicer run -d --pull never nginx:1.27     # use only what the host holds

missing, the default, pulls only an image the host does not hold. never refuses to create an instance whose image the host does not hold, and asks no registry anything, so the create takes only as long as defining the instance and booting it. That makes it the one to use where a create must be quick, with the image pulled beforehand. Over the API, it is the create request’s pull_policy.

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 it was last pulled, or an instance was created or started from it, or garbage collection last found it in use. 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.

/etc/dicerd/config.yaml
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-login

A 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, and so does creating one with --pull always:

$ 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:

/etc/dicerd/config.yaml
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 check

Then 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