
LXD 0.3 has been released. This version provides huge usability improvements over past versions.
Getting started
Here’s an example of quickly getting started on a fresh Ubuntu 15.04 VM:
sudo add-apt-repository ppa:ubuntu-lxc/lxd-daily sudo apt-get update sudo apt-get install lxd sudo lxd-images import lxc ubuntu trusty amd64 --alias ubuntu
(If you are using Ubuntu 14.04 Trusty, you can just add ppa:ubuntu-lxc/daily to get the uptodate packages; If running something else, see the LXD website for instructions.)
lxd-images is a temporary script which downloads an image from images.linuxcontainers.org. You can also manually import any valid image tarball using the ‘lxc image import’ command, however the goal eventually is to have images automatically be downloaded (subject to your consent, i.e. depending on your current network situation) by the lxd package.
You can download and import a debian image by doing:
lxd-images import lxc debian wheezy amd64 --alias debian
You can view the list of available local images by doing:
ubuntu@vlxd:~$ lxc image list +--------+----------+--------+-------------+ | ALIAS | HASH | PUBLIC | DESCRIPTION | +--------+----------+--------+-------------+ | debian | 532fc26c | no | | | ubuntu | 8d39d97e | no | | +--------+----------+--------+-------------+
Once the image is downloaded, you can launch containers based on it:
ubuntu@vlxd:~$ lxc launch debian d1 Creating container...done Starting container...done ubuntu@vlxd:~$ lxc launch ubuntu u2 Creating container...done Starting container...done
Container manipulation
ubuntu@vlxd:~$ lxc list +------+---------+-----------------------+------+ | NAME | STATE | IPV4 | IPV6 | +------+---------+-----------------------+------+ | u1 | RUNNING | 10.0.3.105, 127.0.0.1 | ::1 | | u2 | RUNNING | 10.0.3.78, 127.0.0.1 | ::1 | | d1 | RUNNING | 127.0.0.1 | ::1 | +------+---------+-----------------------+------+ ubuntu@vlxd:~$ lxc exec u2 bash root@u2:~# ping -c 1 10.0.3.105 PING 10.0.3.105 (10.0.3.105) 56(84) bytes of data. 64 bytes from 10.0.3.105: icmp_seq=1 ttl=64 time=0.108 ms --- 10.0.3.105 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.108/0.108/0.108/0.000 ms root@u2:~# exit ubuntu@vlxd:~$ lxc exec u1 -- ps -ef UID PID PPID C STIME TTY TIME CMD root 1 0 0 04:40 ? 00:00:00 /sbin/init root 399 1 0 04:40 ? 00:00:00 upstart-udev-bridge --daemon root 433 1 0 04:40 ? 00:00:00 /lib/systemd/systemd-udevd --dae syslog 547 1 0 04:40 ? 00:00:00 rsyslogd root 570 1 0 04:40 ? 00:00:00 upstart-file-bridge --daemon root 571 1 0 04:40 ? 00:00:00 upstart-socket-bridge --daemon root 1380 1 0 04:40 ? 00:00:00 dhclient -1 -v -pf /run/dhclient root 1446 1 0 04:40 tty4 00:00:00 /sbin/getty -8 38400 tty4 root 1448 1 0 04:40 tty2 00:00:00 /sbin/getty -8 38400 tty2 root 1449 1 0 04:40 tty3 00:00:00 /sbin/getty -8 38400 tty3 root 1458 1 0 04:40 ? 00:00:00 cron root 1490 1 0 04:40 console 00:00:00 /sbin/getty -8 38400 console root 1492 1 0 04:40 tty1 00:00:00 /sbin/getty -8 38400 tty1 root 1530 0 0 04:42 ? 00:00:00 ps -ef
Profiles
Version 0.3 introduces container configuration and profiles. Both are configured using the ‘lxc config’ command. By default, new containers are created with the ‘default’ profile, which has a nic enabled on bridge lxcbr0. You can edit this profile by doing
lxc config profile edit default
which will bring the profile up in an external editor, and update when you save and exit.
To take the default profile out of container u1,
ubuntu@vlxd:~$ lxc config profile list default ubuntu@vlxd:~$ lxc config show u1 Profiles: default ubuntu@vlxd:~$ lxc config profile apply u1 Profile (none) applied to u1 ubuntu@vlxd:~$ lxc config show u1 Profiles:
Now u1 won’t have any nics.
Lets say we want a container to have two nics. We can do this a few ways. We can create a new profile with a second nic, and apply both profiles. We can create a new nic with two nics, and apply only that one. Or we can add the device right to the container, like so:
ubuntu@vlxd:~$ lxc config device add u1 eth1 nic nictype=bridged parent=lxcbr1 Device eth1 added to u1 ubuntu@vlxd:~$ lxc config device list u1 eth1: nic eth0: nic
I’ve only shown local usage in this post. This means I’ve left out the exciting part – remote usage! I’ll leave that for the next post.
In the meantime, you can get lxd from the above-cited ppa, from the lxd website, or from github.
I’m waiting for the next post 🙂
I can start and get a container running, but I can’t get my container reaching the outside world 🙂
That’s not actually what I meant by remotes. If lxc is properly configured, that should “just work”.
Does ‘ifconfig -a’ show a lxcbr0 bridge?
Please try:
sudo lxc-create -t download -n t1 — -d ubuntu -r trusty -a amd64
sudo lxc-start -n t1
and see whether t1 can connect to the outside world:
sudo lxc-attach -n t1 ifconfig -a
sudo lxc-attach -n t1 ping -c1 google.com
FYI at my trusty box, I was having a similar problem as above (no ipv4 address), also failing to exec into it with:
$ sudo lxc exec u1 — ps -f
lxc_container: attach.c: lxc_attach_run_command: 1094 Bad address – failed to exec ‘ps’
Fixed it by upgrading lxc to 1.1.0-0ubuntu1~ubuntu14.04.1~ppa1):
$ apt-cache policy lxc
lxc:
Installed: 1.0.7-0ubuntu0.1
Candidate: 1.1.0-0ubuntu1~ubuntu14.04.1~ppa1
Version table:
1.1.0-0ubuntu1~ubuntu14.04.1~ppa1 0
500 http://ppa.launchpad.net/ubuntu-lxc/lxd-daily/ubuntu/ trusty/main amd64 Packages
*** 1.0.7-0ubuntu0.1 0
500 http://archive.ubuntu.com/ubuntu/ trusty-updates/main amd64 Packages
100 /var/lib/dpkg/status
1.0.3-0ubuntu3 0
500 http://archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages
Suggest adding lxc to the list of packages to install, in above instructions.
Cheers
–jjo
Yeah, that’s why I said to start with a 15.04 vivid box, but indeed trusty with ppa packages will also work. I’ll update this weekend, thanks.
oops, heh – guess my brain just grepped the post for the news and actual commands 🙂
Please help how to remove the device eth0
#lxc config device remove lz eth0
Device eth0 removed from lz
#lxc config show lz
Profiles: default
volatile.eth0.hwaddr = 00:16:3e:6d:e1:cf
volatile.eth1.hwaddr = 00:16:3e:bb:c6:3d
Hm.
the default profile – at least the one auto-installed by lxd – adds a nic and nothing else, so you first could:
lxc config profile apply lz “”
or do ‘lxc config edit lz’ and remove the profile there.
The volatiles staying around was a bug which I hope will be fixed by a (not-yet-completed) merge request (using ‘on delete cascade’)