An extremely common confusion is the distinction between LXD (“LX Daemon” / pronounced “lex-dee”) and LXC (Linux Containers). This post attempts to clear that up.
Overview
From the official site:
LXD isn’t a rewrite of LXC, in fact it’s building on top of LXC to provide a new,
better user experience. Under the hood, LXD uses LXC through liblxc and its Go binding
to create and manage the containers.
It’s basically an alternative to LXC’s tools and distribution template system
with the added features that come from being controllable over the network.
And from here:
LXD is the new LXC experience. It offers a completely fresh and intuitive user experience with a single command line tool to manage your containers. Containers can be managed over the network in a transparent way through a REST API. It also works with large scale deployments by integrating with OpenStack.
LXD was announced in early November 2014 and is still under very active development.
Distinguishing them on the command line
lxd
lxd
is the LXD daemon. For interacting with the daemon (to create and manage containers, for instance), you want to use the lxc
command. You generally don’t want to invoke lxd
directly – unless you need to run lxd init
or something; check man lxd
or lxd --help
for more info on what you can do with running lxd
directly, but once you get it running from your init system, you probably won’t need to invoke it directly again unless you are debugging LXD itself.
The lxc
command is the LXD front-end (“LXD Client” is how I think of it).
However, if you’re trying to use LXD, you should avoid using any commands that start with lxc-
(that’s lxc
, followed by a short hyphen)! These commands are associated with LXC.
lxc
LXC commands start with lxc-
(that’s lxc
followed by a short hyphen). If there’s no hyphen, just the literal command lxc
, that’s associated with LXD.
Packaging
The way LXD and LXC are packaged is distro-specific, but here’s some info on the Ubuntu packages.
The packaging in Ubuntu is a bit confusing unfortunately…
“lxc1” is the “LXC 1.0 user experience” which is what normal people call LXC
“lxc2” is the “LXC 2.0 user experience” which is what normal people call LXD
So if you install “lxc1”, you’ll get the usual LXC tools
“lxc-create/lxc-start/…” and all of those will be at version 2.0.7,
getting all the bugfix and security updates and supported through 2021.
Mixing and matching
It’s generally a bad idea to mix and match LXC and LXD on the same system, in my opinion, because you are likely to get confused, or LXC and LXD might get themselves confused with sharing resources like namespaces, etc. I am not aware of any good use case for using both, so you should really decide on which one to use, and stick with it.
Even better, uninstall the command-line interface for the one you aren’t using, so you don’t accidentally run a command that’s not applicable to the LX{D,C} you intend to use.
Deciding on which to use
It is this user’s opinion that all “green field” (new user/new server) deployments looking at LXC or LXD as a solution should, in 99% of cases, just use LXD. This is especially true if your container host OS is Ubuntu 16.04 or later; you’ll have the most secure, most streamlined experience on this specific OS distro/version combo.
Outside of Ubuntu, it’s a bit easier to deploy LXC than LXD on distros completely outside the Debian/Ubuntu ecosystem, because it has fewer dependencies on kernel features and patches. However, with the proper kernel, it is possible to get a fully working LXD on non-Ubuntu, non-Debian distros. Support for LXD out of the box may improve in the future on some non-Ubuntu distros, but we’ll have to wait and see.
Security
LXC and LXD use the AppArmor LSM and the Secure Computing (seccomp) facility of the Linux kernel for the following purposes:
- To limit the extent to which processes in an unprivileged container can “break out” and affect system-wide resources on the host OS
- To minimize the impact of compromised processes within a container
- To isolate containers’ resources from the host OS while allowing them to access varying levels of resources provided by the host, depending on what the user (from the host side) chooses to allow
Although there are pretty good “default” security measures in place for both LXC and LXD, the isolation is a bit more streamlined and easier to set up from a user perspective with LXD, in my opinion. Security has also been significantly improved over time, so using a patched/supported version of LXD is a very good idea.
On non-Ubuntu systems, the AppArmor profiles might not work (if the kernel lacks certain AppArmor features), which significantly weakens the security of either LXC or LXD. Additionally, Ubuntu ships with a bunch of AppArmor profiles out of the box that other distros might not provide.
Features
Both lxd and lxc have the concept of unprivileged vs. privileged containers. An unprivileged container is designed to be as isolated as possible from the host OS; a privileged container basically implies that with little effort, a root user in the container can “break out” into the host OS, so the barrier between the container and the host is mostly to prevent accidents and encourage good software configuration management practices (similar to Docker).
Unprivileged containers have relatively fewer features than privileged containers in terms of what they can do with the OS and direct hardware access, but that’s a good thing, because many “direct access” type features only make sense when the user working with them is a trusted owner/administrator of the server. You certainly wouldn’t want to give tenants on a multi-tenant container-based VPS hosting box a privileged container. They could easily spy on and interfere with other tenants.
Maintaining this post
Did you know that this post is a Wiki article? This means, once you’ve earned the “Basic” badge, you can edit this post to improve it. If you see an error, or want to add different perspectives or resources, please feel free – but try to keep it on the topic of LXD vs. LXC. For detailed specifics or how-tos for a specific product (LXC or LXD), you are encouraged to create your own Wiki articles.
To learn more about trust levels and badges on Discourse, click here.