This episode sets up the LXC service lifecycle: lxc.start.auto and lxc.start.delay in the config, autostart via the systemd lxc@.service unit or lxc-autostart, running systemd as init inside containers, and orderly shutdown with lxc-stop and lxc-shutdown.

Your containers can now be created, run, limited, and snapshotted. But there's one practical problem: after a host reboot, all containers stay down — unless we configure them. In episode 10 we make containers persist automatically: autostart on boot, management via systemd, and clean shutdown. This is what separates a lab container from real infrastructure services.
Autostart is controlled by two keys in the container config:
lxc.start.auto = 1
lxc.start.delay = 5
lxc.start.order = 100lxc.start.auto = 1 — the container starts automatically on host boot.lxc.start.delay = 5 — a 5-second delay after this container starts (giving the database/network of earlier containers time to stabilize).lxc.start.order = 100 — start order; the smaller the number, the earlier (e.g. database order 50, web order 100).sudo lxc-autostartsudo lxc-autostart -slxc-autostart honors the configured lxc.start.order and lxc.start.delay.
Tip
Order dependencies: if a web server needs a database, give the database lxc.start.order = 10 and the web server lxc.start.order = 100. With lxc.start.delay, you give the database time to finish booting before the web server tries to connect — preventing startup race conditions.
Modern LXC provides the lxc@.service systemd template unit that manages containers as registered services on the host. With this unit, all systemd controls work: enable, start, stop, status, and even startup ordering against other host services.
Enable autostart via systemd for container c1:
sudo systemctl enable lxc@c1.service
sudo systemctl start lxc@c1.serviceCheck its status like any service:
systemctl status lxc@c1.serviceThe advantages of this unit: container logs integrate with the host's journald, and systemd can guarantee start ordering against other units (e.g. lxc@db must run before the host nginx).
lxc-autostart — simple, uses the container config settings (lxc.start.auto), suitable for all-containers-boot scenarios.lxc@.service — explicit per container, can be systemctl enable/disabled individually, and integrates with systemd dependencies.Many users use both together: lxc.start.auto for default behavior, the systemd unit for granular control. Be careful that duplicate configuration doesn't start a container twice — it's usually safe because LXC prevents double starts, but still check systemctl status.
Modern containers (Ubuntu 24.04, Debian, Fedora) run systemd as init (PID 1) inside. That means services inside the container are managed like a regular Linux host: systemctl enable/start/status work normally inside the container.
Enter and manage services:
lxc-attach -n c1 -- systemctl status sshd
lxc-attach -n c1 -- systemctl enable --now sshd
lxc-attach -n c1 -- systemctl list-units --state=runningNote
For fully running systemd containers, the host should also use systemd and support systemd-friendly containers (not just lxc.execute). The official download template already produces systemd containers that boot correctly. Don't use the legacy lxc-execute template for services that need a full init.
Once a service runs inside the container, access it from outside via port forwarding (episode 6) or directly via the container IP if the network is bridged:
lxc-info -n c1 -iHlxc-shutdown sends a signal to the container's init (like pressing the power button on a desktop): systemd receives the shutdown command, stops services cleanly, then powers off. This is the most correct way to stop a container.
lxc-shutdown -n c1lxc-stop stops the container forcefully — equivalent to pulling the power cable. Use it when a container hangs or lxc-shutdown doesn't respond.
lxc-stop -n c1lxc-shutdown so services close themselves down cleanly (important for databases).lxc-stop, then think about why shutdown didn't work.lxc-shutdown -n c1 -t 10 || lxc-stop -n c1Key takeaways:
lxc.start.auto = 1 makes a container boot with the host; lxc.start.order and lxc.start.delay set the order and delay.lxc-autostart processes all containers with start.auto; lxc-autostart -s shuts them all down.lxc@.service unit integrates containers into the host systemd with dependencies and journald logging.systemctl.lxc-shutdown for orderly shutdown, lxc-stop as a last resort.In the next episode 11 we'll cover bind & mount host paths — lxc.mount.entry for mounting host directories into the container, mount options like ro, and the real-world case of sharing data directories and device access.