Ceci est une ancienne révision du document !
Canonical has made Linux containers really easy with Snaps. Don’t get me wrong, we still have to configure it, but if you look here, it’s as simple as 1,2,3: https://canonical.com/lxd/install (f you try to install the apt, it will launch the Snap package anyway). OK all you Ubuntu mechanics, grab that virtual spanner and let’s get cracking! That includes YOU, lazy bones; fire up your terminal and rev those engines! Before you follow me down this rabbit hole, let's install lxd and then I will take you through our configuration. Start by making sure all your Snaps are up-to-date: sudo snap refresh - and let it do its thing, before running: sudo snap install lxd As you can see from Canonical’s site, there isn’t much to do other than initialise the application. Type: lxd init and let’s navigate the questions together? (We do this only the very first time, so don’t worry too much). We pretty much stick with the defaults. However, you may name your storage pool anything you like; for our tutorial, I’ll just name it fcmpool, or something similar, and we will use dir instead of zfs. We can type out the yes & no, but we can also just press enter to confirm the defaults. I will do both so you can see. It is only IPv6 where I select “none”, and once you are done, you have the option of printing a YAML file for future reference.
You can check if it is operational - ps -aux | grep lxd and you should see that shown below right. Now that we have LXD running, let’s confirm there are no ‘running’ containers: lxc list We can also now confirm that there are no images on the system: lxc images list Great, a blank slate! (Ok not really, we have some repos configured for us); lxc remote list - to see them. If you hold down the CTRL key and click on the very first link, it will open that link in a browser for you (https://images.lxd.canonical.com/). You may see that images are built daily, but even then, these are not “official” images. We can even go look on: https://images.linuxcontainers.org/ - to see what is available for us to play with.
Now, back to the very first page link ^^^^^ right at the top, and you will see the syntax is: lxc launch <image_server>:<image_name> <instance_name> with an example: lxc launch ubuntu:22.04 ubuntu-container You just have to remember ‘lxc launch’, but let’s go ahead and do the thing… you know, copy/paste from the website. OR you can try the command they give you once you typed lxc list. I’m not going to type it here, just to make sure you are ‘doing’, when following along, as this is all going to be ‘hands-on’. Woot! If you are here with me, well done! If you are struggling to launch anything other than the examples, type lxc list again and peruse the output. You will see NAME, URL, PROTOCOL … That first column, NAME, tells you how to check out something from the repo. If I look at the community image server, you will see that it starts with ALMA linux in the distribution column, then we have ‘release’, ‘architecture’, ‘variant’, and so forth. We will use ALPINE as an example as it is tiny. Keep in mind that by the time this publishes, the versions would have moved on, so do not just blindly copypasta me here, I am trying to teach you to fish on your own. So, lxc launch (you remember this) images: (the name in the first column) alpine/3.20 (distribution name / version) apline (the name on my system, can be anything) So are we all on the same page? Good! I installed Ubuntu and Alpine, so you can see the difference in size: 241MB vs 3MB, so those of you on metered or slow connections, stick to Alpine, so we can go forward. Let’s drive this sucker!
To stop our running container, we simply say ‘stop’
lxc stop alpine
(You can use tab completion if you were stopping ‘inviting-bird’, for instance).
So if we stop something, we can start it again with start; I’ll let you figure that one out…
We can also ‘delete’ a container, as long as it is in the ‘stopped’ state. If you have 2, like I do, try to delete them both as is – and you should get an error on one.
lxc delete alpine
I do not recommend using the - -force Luke! You will see it in the error message.
Know that if you delete a container, you do *not automatically delete the image also, so don’t be afraid to delete both; you have the image, so to spin up a clone is quicker than you think! To delete images, you can use ‘image delete’ so: lxc image delete 58ec (in my case).
Pay attention to your image’s fingerprint, you need to type up only to where it becomes unique, you do not have to type out the whole shebang.
You may have noticed that once you downloaded the image, it spun up and was ready to use immediately. If you do not want this behaviour, you can ‘copy’ the image only. lxc image copy images:alpine/3.17 local: –alias alpinelocal (list your images and see). Now if/when I need alpine, I can simply say: lxc launch alpinelocal jokeapp This would give it a alias of jokeapp if I had an app that dispensed jokes, for instance. That’s it, our first dip into the ocean of containers, right on your Ubuntu desktop! Come see me next issue and we can continue, right here on FCM! As always, mistakes to: misc@fullcirclemagazine.org