Got Unprivileged Going on VM Ubuntu 18.04 (lxc 3.0.3)

I tried a large variety of alternatives and had no success and much fussing. This worked, and it is exactly what is on the Getting Started page, with a bit more details. I found no variation that would work, and it was not easy to even figure out these details, so I figure posting this might help others for others.

I’m on OSX. I got virtualbox going (probably from here).

I used vagrant to get a VM up.

This Vagrantfile worked:

Vagrant.configure("2") do |config|
    config.vm.box = "ubuntu/bionic64"
end

No other versions of linux were working and i tried many. Use that one. Vagrant and Virtualbox are easy to get going. Vagrant has good docs:

Here’s the image that worked:

https://app.vagrantup.com/ubuntu/boxes/bionic64

Get into the vm via vagrant ssh (vagrant up && vagrant ssh).

Refresh the list of available packages:

sudo apt update

Install lxc:

sudo apt-get install lxc

Configure it like this:

mkdir -p ~/.config/lxc
echo "$USER veth lxcbr0 2" | sudo tee -a /etc/lxc/lxc-usernet
cp /etc/lxc/default.conf ~/.config/lxc/default.conf

You’ll need to edit the user-scoped config (~/.config/lxc/default.conf) as described on the Getting Started page, and make sure to set the uid/gid to match the vagrant user, which is found in /etc/subuid, /etc/subgid, and looks like this, “165536”. Get it like this:

cat /etc/subuid | awk -F: '/vagrant/ { print $2 }'

Then edit it:

vi ~/.config/lxc/default.conf 

Then download the images. I had to run this twice. The first time it failed to connect to the gpg key server (or something):

lxc-create -t download -n my-container

Start it up, check it out and get in there:

lxc-start -n my-container -d
lxc-info -n my-container
lxc-ls -f
lxc-attach -n my-container

Everything seems to work perfectly.