Some Bits: Nelson's log

LXC by hand

Some rough notes on setting up LXC on a generic Ubuntu system with the command line tools. No Proxmox. I mostly followed this guide and made it difficult for myself by setting up an unprivileged container. This is easier if you’re root.

  1. sudo apt install lxc
  2. Follow the instructions in “Basic unprivileged usage” that have you creating a ~/.config/lxc/default.conf and as root adding permissions for networking to /etc/lxc/lxc-usernet.
  3. Run lxc-update-config -c ~/.config/lxc/default.conf
    This is not mentioned in the Ubuntu docs but seems necessary, I found it in a comment here.
  4. Create a container: lxc-create -t download -n u1 -h
  5. Configure it interactively (I couldn’t figure out command line switches). The list of containers is here. I chose alpine, 3.18, arm64.
  6. Start it: lxc-start -n u1
  7. Connect to it: lxc-attach -n u1

On the container:

  1. Verify networking works: ping 8.8.8.8 (note that “ping” can be fraught but it worked for me.) ip a shows me a 10.* address, not my usual LAN subnet. I guess some routing is involved?
  2. Verify you have process isolation: ps -axu. It’s a list of a few root processes just for the Alpine container, nothing for the host.

On the host:

  1. Verify user ID mapping: ps -axu | grep /sbin/init. I have some processes with a new user 100000.
  2. Learn some things about the container:
    lxc-info -n u1
  3. Check the container’s files in $HOME/local/share/lxc

I’m having a hard time getting any system stats about the containers. lxc-top reports nonsense, free inside the container shows the host system stats (yes, lxcfs is installed in the host), lxc-info does not show memory usage despite all the docs saying it should.

One thing I notice is all the help pages I find online in my searches are ~2014 era. I suspect most people have moved on from LXC to LXD or Docker or whatever. I’m only tinkering with LXC because that’s what Proxmox uses. But then they’ve built their own pct tool for managing things.

Comments

pauljbardo 

Was this an exercise in seeing how it was done, or was there some reason not to use ttek's "Ubuntu LXC" script?

yes, mostly an exercise. Although for a simple Proxmox Ubuntu LXC I'd just use their template, not a tteck script.