Image Caching

Overview

To speed up the provisioning of the OpenShift cluster and to minimize network traffic, container images can be cached on the host. These images can then be imported into the running Docker daemon, either explicitly on request or implicitly during minishift start. The following sections describe image caching and its configuration in more detail.

The format in which images are cached has changed with Minishift version 1.10.0. Prior to 1.10.0 the images were stored as tar files. As of 1.10.0, images are stored in the OCI image format.

If you used image caching prior to Minishift 1.10.0, your cache will need to be recreated. If you want to remove the obsolete pre 1.10.0 images, you can clear your cache via:

  1. $ minishift delete clear-cache

Explicit Image Caching

Minishift provides the image command together with its sub-commands to control the behavior of image caching. To export and import images from the Docker daemon of the Minishift VM, use minishift image export and minishift image import.

Importing and Exporting Single Images

Once the Minishift VM is running, images can be explicitly exported from the Docker daemon:

  1. $ minishift image export <image-name-0> <image-name-1> ...
  2. Pulling image <image-name-0> .. OK
  3. Exporting <image-name-0>. OK
  4. Pulling image <image-name-1> .. OK
  5. Exporting <image-name-2>. OK

Images which are not available in the Docker daemon will be pulled prior to being exported to the host.

To import previously cached images, use the minishift image import command:

  1. $ minishift image import <image-name-0> <image-name-1> ...
  2. Importing <image-name-0> . OK

Listing Cached Images

The minishift image list command lists either the currently cached images or the images available in the Minishift Docker daemon.

To view currently cached images on the host:

  1. $ minishift image list
  2. openshift/origin-docker-registry:v3.6.0
  3. openshift/origin-haproxy-router:v3.6.0
  4. openshift/origin:v3.6.0

To view images available in the Docker daemon:

  1. $ minishift image list --vm
  2. openshift/origin-deployer:v3.6.0
  3. openshift/origin-docker-registry:v3.6.0
  4. openshift/origin-haproxy-router:v3.6.0
  5. openshift/origin-pod:v3.6.0
  6. openshift/origin:v3.6.0

Persisting Cached Image Names

In order to avoid having to type the image names explicitly as part of the image export or image import command, you can store a list of image names for import and export in the persistent configuration.

Use minishift image cache-config view to view the list of currently configured images and minishift image cache-config add to add images to the list:

  1. $ minishift image cache-config view
  2. $ minishift image cache-config add alpine:latest busybox:latest
  3. $ minishift image cache-config view
  4. alpine:latest
  5. busybox:latest

To remove images from the list use minishift image cache-config remove:

  1. $ minishift image cache-config remove alpine:latest
  2. $ minishift image cache-config view
  3. busybox:latest

Once the image names are stored in the persistent configuration, you can run minishift image export and minishift image import without any arguments.

Exporting and Importing All Images

You can export and import all images using the --all flag. For the export command, this means that all images currently available on the Docker daemon will be exported to the host. For the import command, it means that all images available in the local Minishift cache will be imported into the Docker daemon of the Minishift VM.

Exporting and importing all images can take a long time and locally cached images can take up a considerable amount of disk space. We recommend using this feature with caution.

Implicit Image Caching

Image caching is enabled by default for Minishift. It occurs in a background process after the minishift start command is completed for the first time. Once the images are cached under $MINISHIFT_HOME/cache/images, successive Minishift VM creations will use these cached images.

To disable this feature you need to disable the image-caching property in the persistent configuration using the minishift config set command:

  1. $ minishift config set image-caching false

Implicit image caching will transparently add the required OpenShift images to the list of cached images as specified per cache-images configuration option. See Persisting Cached Image Names.

Each time an image exporting background process runs, a log file is generated under $MINISHIFT_HOME/logs which can be used to verify the progress of the export.

You can re-enable the caching of the OpenShift images by setting image-caching to true or removing the setting altogether using minishift config unset:

  1. $ minishift config unset image-caching

Delete Image from local cache

Images are cached under $MINISHIFT_HOME/cache/images and stored as sha256 blob along with an index which contains detail about matching sha with image name.

To delete an image from the local cache, use the minishift image delete command:

  1. $ minishift image delete <image-name-0> <image-name-1> ...
  2. Deleting <image-name-0> from the local cache OK
  3. Deleting <image-name-1> from the local cache OK