Managing LXD images
-
As @scottalanmiller tells us in the introductory post, lxd is completely image based. Each new container we create must be based from an image, either manually made or premade and downloaded from a remote location.
After installation, lxd by default sets us with remote image locations so we can start downloading images to our local store. We can check the default remote list with the following command.
~$ lxc remote list +-----------------+------------------------------------------+---------------+--------+--------+ | NAME | URL | PROTOCOL | PUBLIC | STATIC | +-----------------+------------------------------------------+---------------+--------+--------+ | images | https://images.linuxcontainers.org | simplestreams | YES | NO | +-----------------+------------------------------------------+---------------+--------+--------+ | local (default) | unix:// | lxd | NO | YES | +-----------------+------------------------------------------+---------------+--------+--------+ | ubuntu | https://cloud-images.ubuntu.com/releases | simplestreams | YES | YES | +-----------------+------------------------------------------+---------------+--------+--------+ | ubuntu-daily | https://cloud-images.ubuntu.com/daily | simplestreams | YES | YES | +-----------------+------------------------------------------+---------------+--------+--------+
To check the images available in each remote, we can run
lxc image list remotename:
and a list of all available image containers will be listed, but this is many times not practical due to the amount of images available in the remotes. So you can just visit the url shown in the remote list in your browser of choice to view the available images.From the cli
~$ lxc image list images:
Visiting the remote url: https://images.linuxcontainers.org
To get images to our local store and start building containers the basic command is
lxc image copy remoteName:imageDistribution/imageRelease/imageArchitecture local:
imageArchitecture being optional.This basic command does its job just fine but has a few drawbacks in my opinion. It forces us to call the
imageDistribution/imageRealease
image name each time we want to create a container and the image must be downloaded again manually if we want to have the latest container.How can we fix this, easy addding two extra parameters to our basic image download command. Here is an example that will be downloading a Fedora/27 image from the "images:" remote, giving it our custom alias and having it auto updating daily.
~$ lxc image copy images:fedora/27 local: --alias f-27 --auto-update
Giving our images an alias has two benefits, shorter commands when creating containers and the ability to delete images by the alias instead of deleting by using the image Fingerprint which is not user friendly.
# List images in our local store and compare the alias vs fingerprint ~$ lxc image list +---------+--------------+--------+-----------------------------------------+--------+----------+-----------------------------+ | ALIAS | FINGERPRINT | PUBLIC | DESCRIPTION | ARCH | SIZE | UPLOAD DATE | +---------+--------------+--------+-----------------------------------------+--------+----------+-----------------------------+ | f27 | b25c1b1b6831 | no | Fedora 27 amd64 (20171201_01:27) | x86_64 | 63.61MB | Dec 1, 2017 at 3:01am (UTC) | +---------+--------------+--------+-----------------------------------------+--------+----------+-----------------------------+
Finally to create and start our container based on our Fedora 27 image we just run.
~$ lxc launch f27 yourcontainername Creating yourcontainername Starting yourcontainername ~$