LXD is sweet. To create a ubuntu xenial container, just do
lxc launch ubuntu:xenial x1
The remote xenial image will be automatically fetched on the first use, and cached for future uses. Nifty. Hmm… but what then?
There are three server settings which guide how images are treated after their initial use. And setting these can make the difference between frequent higher bandwidth use and more uptodate images.
The discussion will be eased if we define a term: a ‘cached’ image is one which is created implicitly as part of a container creation. I.e. the first time that you do
lxc launch ubuntu:trusty t1
lxd will fetch the ubuntu:trusty image, implicitly creating a cached copy on the target remote. In contrast, you can explicitly create a non-cached image using
lxc image copy ubuntu:wily local: –alias wily
As you might expect, these two images are treated a bit differently. The first is cached for a while to save on future bandwidth, but it’s a second class citizen compared to the second image, which the user explicitly requested.
With that in mind, as I said earlier, there are three configuration settings which guide image behavior.
First there is the cached image auto update setting,
lxc config set images.auto_update_cached true
Any cached images which are created while this is set to true will be auto-updated. Note that setting this to true after creating a container will not change that pre-existing cached image’s auto update setting.
For explicitly created images, you can instead specify auto-update manually using
lxc image copy ubuntu:wily local: –alias wily –auto-update
The second setting is remote_cache_expiry:
lxc config set images.remote_cache_expiry 1
This specifies, in days, how long an unused cached image is kept in the cache before it is flushed. If this value is not specified, then it defaults to 10 days. Note that explicitly copied images are not expired.
Finally, auto_update_interval specifies how many hours should pass between lxd’s checks for whether a cached image should be updated. Setting this value to 0 disables the checks. So if you find yourself temporarily on a slow, expensive, 3G router, you may want to
lxc config set images.auto_update_interval 0
to save yourself from accidentally downloading a few hundred megs or more of updated image contents. On the other hand, when back at the datacenter, you might want to
lxc config set images.auto_update_interval 1
to keep as in sync as possible.