[lxc-users] [FWIW] Autostart lxc (lxd) containers
Mark Constable
markc at renta.net
Sat May 16 13:04:01 UTC 2015
This info was hard (for me) to come by so maybe it will help someone
else just starting out with lxc (lxd) containers. I'm using wily on a
laptop host with btrfs. Condensed shell history as non-root user...
lxc remote add upstream images.linuxcontainers.org
lxc image list upstream:
lxc image copy upstream:/ubuntu/wily/amd64 local: --alias=wily
lxc image list
lxc launch wily w1
lxc exec w1 bash
/etc/init.d/networking restart
apt update
apt --no-install-recommends install nano openssh-server git wget
nano /etc/rc.local
# add below before the exit 0
sleep 5 && /etc/init.d/networking restart
passwd ubuntu
halt
On the host add this systemd unit file (change w1 to your container name)...
~ cat /etc/systemd/system/multi-user.target.wants/lxd-autostart.service
[Unit]
Description=Start lxc containers created with lxd
After=lxd.service
Requires=lxd.service
[Service]
ExecStart=/usr/bin/lxc start w1
[Install]
WantedBy=multi-user.target
Now when I reboot my host laptop I get...
markc at markc ~ lxc list
+------+---------+-------------+------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | EPHEMERAL | SNAPSHOTS |
+------+---------+-------------+------+-----------+-----------+
| w1 | RUNNING | 192.168.0.6 | | NO | 0 |
+------+---------+-------------+------+-----------+-----------+
And ssh ubuntu at 192.168.0.6 works. All a bit of a kludge but it's enough
for me to continue working with unprivileged containers rather than have
to rely on legacy lxc.
More information about the lxc-users
mailing list