LXC (Linux Containers) is a lightweight virtualization technology that allows you to run multiple isolated Linux systems (containers) on a single host. The lxd
package provides the tools to manage LXC containers effectively. Below are the steps to install and configure LXC using Snap.
The Snap package manager simplifies the installation process by providing a pre-packaged version of LXD (the daemon managing LXC containers).
sudo snap install lxc
After installation, you need to initialize LXD to configure its environment.
sudo lxd init
dir
(directory-based storage) or zfs
/btrfs
(advanced storage backends). For beginners, dir
is sufficient.lxdbr0
) or use an existing one.
LXD provides a web-based user interface (UI) for managing containers. To enable it:
Enable the Web UI:
sudo snap set lxd ui.enable=true
Restart LXD to Apply Changes:
sudo snap restart --reload lxd
Set HTTPS Address: To make the web UI accessible, configure the HTTPS address:
lxc config set core.https_address :7443
7443
on all network interfaces (0.0.0.0
). You can replace :7443
with a specific IP address (e.g., 192.168.1.10:7443
) if needed.Access the Web UI: Open a browser and navigate to:
https://<server-ip>:7443
<server-ip>
with the IP address of your server.7443
:
sudo ufw allow 7443/tcp
Snap Permissions:
If you encounter permission issues, ensure your user is part of the lxd
group:
sudo usermod -aG lxd $USER
newgrp lxd
Web UI Not Accessible: Verify that the LXD service is running:
sudo systemctl status snap.lxd.daemon
Port Conflicts:
If the default port (e.g., 7443
) is already in use, choose a different port:
lxc config set core.https_address :8443
Find the Web UI Port on the Server:
To confirm which port the LXD Web UI is listening on, use the netstat
command:
sudo netstat -nltp | grep lxd
lxd
.tcp6 0 0 :::8443 :::* LISTEN 1518185/lxd
8443
.core.https_address
setting:
lxc config set core.https_address :<desired-port>
Firewall Rules:
Ensure the firewall allows traffic on the configured Web UI port. For example, if the Web UI is on port 8443
:
sudo ufw allow 8443/tcp
Self-Signed Certificate Warnings: If you see SSL certificate warnings when accessing the Web UI, it is likely due to the self-signed certificate used by LXD. You can either:
To securely access the LXD Web UI using certificate-based encryption, you can use a .pfx
(Personal Information Exchange) file. This method ensures that only authorized users with the correct certificate can access the Web UI. Follow the steps below to configure this on macOS:
Download the .pfx
files from the Google drive Link
.pfx
File to Keychain AccessLocate the .pfx
File:
.pfx
file from your LXD server or generate one if necessary..pfx
file contains both the private key and the certificate.Import the .pfx
File:
Applications > Utilities > Keychain Access
).File > Import Items
..pfx
file and click Open.Configure Trust Settings:
Allow All Apps to Use the Certificate:
Close and Reopen Google Chrome:
Access the Web UI:
https://<server-ip>:<port>
Replace <server-ip>
with the IP address of your server and <port>
with the configured HTTPS port (e.g., 7443
). 7443
on server001 and 8443
on server001 and server003.Select the Certificate:
.pfx
file is correctly imported and trusted..pfx
file is properly imported and trusted in Keychain Access..pfx
file..pfx
file.