Debian 9 64 Bits – Mise en place LXD
You are now root inside a LXD container with a nested LXD installed inside it.
Initial startup can take a few seconds due to having to generate SSL keys on a rather busy system.
Further commands should then be near instantaneous.
You’re welcome to just poke around and discover LXD through its manpage and –help option.
Or you can follow this step by step tutorial instead which will get you through LXD’s main features.
Your first container
LXD is image based, however by default no images are loaded into the image store as can be seen with:
LXD knows about 3 default image servers:
- ubuntu: (for Ubuntu stable images)
- ubuntu-daily: (for Ubuntu daily images)
- images: (for a bunch of other distributions)
The stable Ubuntu images can be listed with:
To launch a first container called « first » using the Ubuntu 18.04 image, use:
Your new container will now be visible in:
Running state details and configuration can be queried with:
By default your container comes with no resource limitation and inherits from its parent environment. You can confirm it with:
To apply a memory limit to your container, do:
And confirm that it’s been applied with:
LXD supports snapshoting and restoring container snapshots.
Before making a snapshot, lets do some changes to the container, for example, updating it:
Now that the container is all updated and cleaned, let’s make a snapshot called « clean »:
Let’s break our container:
Confirm the breakage with (then exit):
And restore everything to the snapshotted state:
And confirm everything’s back to normal (then exit):
As your probably noticed earlier, LXD is image based, that is, all containers must be created from either a copy of an existing container or from an image.
You can create new images from an existing container or a container snapshot.
To publish our « clean » snapshot from earlier as a new image with a user friendly alias of « clean-ubuntu », run:
At which point we won’t need our « first » container, so just delete it with:
And lastly we can start a new container from our image with:
Accessing files from the container
To pull a file from the container you can use the « lxc file pull » command:
Let’s add an entry to it:
And push it back where it came from:
You can also use this mechanism to access log files:
We won’t be needing that container anymore, so stop and delete it with:
Use a remote image server
The lxc client tool supports multiple « remotes », those remotes can be read-only image servers or other LXD hosts.
LXC upstream runs one such server at https://images.linuxcontainers.org which serves a set of automatically generated images for various Linux distributions.
It comes pre-added with default LXD but you can remove it or change it if you don’t want it.
You can list the available images with:
And spawn a new Centos 7 container with:
Confirm it’s indeed Centos 7 with:
And delete it:
The list of all configured remotes can be obtained with:
Interact with remote LXD servers
For this step, you’ll need a second demo session, so open a new one here
Copy/paste the « lxc remote add » command from the top of the page of that new session into the shell of your old session.
Then confirm the server fingerprint for the remote server.
Note that it may take a few seconds for the new LXD daemon to listen to the network, just retry the command until it answers.
At this point you can list the remote containers with:
And its images with:
Now, let’s start a new container on the remote LXD using the local image we created earlier.
You now have a container called « fourth » running on the remote host « tryit ». You can spawn a shell inside it with (then exit):
Now let’s copy that container into a new one called « fifth »:
And just for fun, move it back to our local lxd while renaming it to « sixth »:
And confirm it’s all still working (then exit):
Then clean everything up:
We hope this gave you a good introduction to LXD, its capabilities and how easy it is to use.
You’re welcome to use the demo service as long as you want to try LXD and play with the latest features.