Bobcares

LXC Autostart Unprivileged Containers | Tutorial

by | Nov 28, 2023

Learn how to set up autostart for unprivileged LXC containers. Our LXC/LXD Support team is here to help you with your questions and concerns.

How to Set Up Autostart for Unprivileged LXC Containers

Did you know that unprivileged containers in LXC have lower privileges?

In other words, they run as a regular user and not as a root user.

How to Set Up Autostart for Unprivileged LXC Containers

Furthermore, autostarting these containers comes in handy if we want to make sure specific services or applications in the containers are available once the host system starts.

Let’s take a quick look at how to configure autostart for unprivileged LXC containers:

  1. To begin with, log into the Proxmox VE web interface.
  2. Then, head to the “Local” node.
  3. Now, click “LXC” and we will be able to see a list of our containers.
  4. Next, we have to choose the unprivileged container for which we want to set up autostart.
  5. At this point, head to the Options tab in the container details view.
  6. Then, locate the “Autostart” or “Start at boot” option and set it to “Yes” or “Enable.”
  7. Finally, save the changes.

Alternatively, we can accomplish the same goal via the command line as seen here:

  1. Run the following command to enable autostart for an unprivileged LXC container:

    pct set ID_or_Name_of_Unprivileged_Container --onboot yes

    This command will change the container configuration by setting the “onboot” option to “yes”.

  2. Then, apply the changes with this command:

    pct applyconfig ID_or_Name_of_Unprivileged_Container

How to use systemd user mode to Autostart Unprivileged LXC Containers

  1. First, create the file ~/.config/systemd/user/lxc-autostart.service in the home of the user with the LXC containers:

    [Unit] Description="Lxc-autostart for lxc user" [Service] Type=oneshot ExecStart=/usr/bin/lxc-autostart ExecStop=/usr/bin/lxc-autostart -s RemainAfterExit=1 [Install] WantedBy=default.target

  2. Now, run this as the user:

    systemctl --user enable lxc-autostart

    Here, the –user option informs systemctl that we are using in user mode.

  3. Then, run the following command:

    sudo loginctl enable-linger $user

    Here, $user is the name of the user that has the LXC containers.

    Our experts would like to point out that systemd has to start a systemd user instance for $user at boot. Otherwise, it will start only at the moment $user logs in.

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

In brief, our Support Experts demonstrated how to set up autostart for unprivileged LXC containers.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.