Getting Started with LXD on Ubuntu 17.04



  • LXD and LXC are the standard full stack container virtualization (operating system level virtualization or Type C hypervisor) on Ubuntu Linux. Getting started with them is quite easy. LXD is really a management system for LXC, not a competing technology.

    First we have to install the packages.

    sudo apt-get install lxd
    

    Then we need to initialize the system.

    sudo lxd init
    

    This initialization script will ask you a few basic questions about how you would like your container environment to be set up. You can often just accept the defaults here. Once you have completed the handful of questions, your LXD/LXC container environment is ready for you to create your very first container.

    LXD works from images. To see a list of images currently available to you, you can use lxc image list. This is just the list that is already downloaded. You can get many more online.

    lxc image list
    +-------+--------------+--------+---------------------------------------------+--------+----------+-------------------------------+
    | ALIAS | FINGERPRINT  | PUBLIC |                 DESCRIPTION                 |  ARCH  |   SIZE   |          UPLOAD DATE          |
    +-------+--------------+--------+---------------------------------------------+--------+----------+-------------------------------+
    |       | 8220e89e33e6 | no     | ubuntu 16.04 LTS amd64 (release) (20170721) | x86_64 | 153.94MB | Jul 21, 2017 at 11:32pm (UTC) |
    +-------+--------------+--------+---------------------------------------------+--------+----------+-------------------------------+
    |       | f04873cda185 | no     | ubuntu 17.04 amd64 (release) (20170720)     | x86_64 | 158.71MB | Jul 23, 2017 at 12:08am (UTC) |
    +-------+--------------+--------+---------------------------------------------+--------+----------+-------------------------------+
    

    Now that we can see what we have available to us, we will make an Ubuntu 17.04 LXC container / VM. This is as simple as specifying that we want to create a container and telling LXC what name we want to use.

    lxc launch ubuntu:17.04 my-machine
    

    That's all that it takes. We can now ask LXC to show us a list of our machines. If the above command worked, we would expect it to show us one machine.

    lxc list
    
    +------------+---------+-----------------------+-----------------------------------------------+------------+-----------+
    |    NAME    |  STATE  |         IPV4          |                     IPV6                      |    TYPE    | SNAPSHOTS |
    +------------+---------+-----------------------+-----------------------------------------------+------------+-----------+
    | my-machine | RUNNING | 10.191.188.180 (eth0) | fd42:6854:fba9:9f7f:216:3eff:fe8a:adf3 (eth0) | PERSISTENT | 0         |
    +------------+---------+-----------------------+-----------------------------------------------+------------+-----------+
    

    There we go. We can see our new container already up and running, waiting for us to use it. LXC makes this very easy for us with the name, state (that the VM is running) IP address all there for us to easily see.

    Of course, a VM that we cannot access does us no good at all. Accessing our VM can be done via SSH or any normal means once all of our plumbing is in place. But for getting started we probably want to access it directly from the LXC console. No problem. All we need to do is execute our shell of choice (bash in this example) on the container and we will be dropped into direct access.

    lxc exec my-machine bash
    

    Now we are in the bash shell on my-machine. Just as if we were sitting right at its console. You can manage the box like normal, it is a full virtual machine. When you are done, just "exit" to leave bash as normal and you will return to your host system.

    Of course you can do more than just execute bash in this manner. Try some of these commands:

    lxc exec my-machine apt-get update
    lxc exec my-machine apt-get -y dist-upgrade
    lxc exec uptime
    

    When you no longer want your container running, you can stop it easily.

    lxc stop my-machine
    

    You can start it easily, too.

    lxc start my-machine
    

    If your machine is stopped and you are tired of your container and want to delete it, that's easy too.

    lxc delete my-machine
    

    There you have it, a very simple, but powerful, introduction to LXD containers on Ubuntu Linux. Enough to get you up and running and production with containers immediately.



  • If, for some reason, you have no local images, you can pull them from a remote server so that you can install locally. For Ubuntu 17.04, try this command:

    lxc image copy ubuntu:17.04 local:


  • I was considering to test this stuff too. Also in my search on the web I've discovered that even virtmanager+libvirt can manage lxc containers. This is handy as you just need the same tooling you use for kvm/xen



  • @matteo-nunziati said in Getting Started with LXD on Ubuntu 17.04:

    I was considering to test this stuff too. Also in my search on the web I've discovered that even virtmanager+libvirt can manage lxc containers. This is handy as you just need the same tooling you use for kvm/xen

    Yes, lots of good options. I like the command line for what I do, fast and easy and light. I'm using this on my desktop now.



  • @scottalanmiller
    Are you running KVM and LXD on the same machine?



  • @black3dynamite said in Getting Started with LXD on Ubuntu 17.04:

    @scottalanmiller
    Are you running KVM and LXD on the same machine?

    I am, yes.



  • @scottalanmiller said in Getting Started with LXD on Ubuntu 17.04:

    @black3dynamite said in Getting Started with LXD on Ubuntu 17.04:

    @scottalanmiller
    Are you running KVM and LXD on the same machine?

    I am, yes.

    Wouldn't this be the expectation? in many if not most cases?



  • @dashrender said in Getting Started with LXD on Ubuntu 17.04:

    @scottalanmiller said in Getting Started with LXD on Ubuntu 17.04:

    @black3dynamite said in Getting Started with LXD on Ubuntu 17.04:

    @scottalanmiller
    Are you running KVM and LXD on the same machine?

    I am, yes.

    Wouldn't this be the expectation? in many if not most cases?

    If you know my particular case, yes it would be an expectation. In a more common scenario, no, not so much.



  • @scottalanmiller said in Getting Started with LXD on Ubuntu 17.04:

    @dashrender said in Getting Started with LXD on Ubuntu 17.04:

    @scottalanmiller said in Getting Started with LXD on Ubuntu 17.04:

    @black3dynamite said in Getting Started with LXD on Ubuntu 17.04:

    @scottalanmiller
    Are you running KVM and LXD on the same machine?

    I am, yes.

    Wouldn't this be the expectation? in many if not most cases?

    If you know my particular case, yes it would be an expectation. In a more common scenario, no, not so much.

    Wouldn't you typically have LXD on a hypervisor?



  • @dashrender said in Getting Started with LXD on Ubuntu 17.04:

    @scottalanmiller said in Getting Started with LXD on Ubuntu 17.04:

    @dashrender said in Getting Started with LXD on Ubuntu 17.04:

    @scottalanmiller said in Getting Started with LXD on Ubuntu 17.04:

    @black3dynamite said in Getting Started with LXD on Ubuntu 17.04:

    @scottalanmiller
    Are you running KVM and LXD on the same machine?

    I am, yes.

    Wouldn't this be the expectation? in many if not most cases?

    If you know my particular case, yes it would be an expectation. In a more common scenario, no, not so much.

    Wouldn't you typically have LXD on a hypervisor?

    LXD is a Type-C hypervisor, so while having it on top of a Type 1 is common, having it on bare metal is also common.