This how-to guide will take you through the installation steps to run the LXD dashboard in an LXC container on your system. This guide will assume that your system already has LXD installed and configured.
Start by launching a new instance using the official Ubuntu 20.04 image. To launch the new instance and name it lxd-dashboard use the following command:
$ lxc launch ubuntu:20.04 lxd-dashboard
This will create a base container to use to install the LXD dashboard. Once the command finishes the container should be running. Now it is time to connect into the container and setup the software. Use the following command to obtain a bash shell connection to the instance, use the exit command at anytime to leave the shell:
$ lxc exec lxd-dashboard /bin/bash
The following commands will now be run inside the lxd-dashboard container. Verify that the terminal prompt reads root@lxd-dashboard:~# before installing any software. The LXD dashboard uses Nginx and PHP for the webserver platform and SQLite as a database. To install these packages use the following command:
$ apt update && apt install nginx php-fpm php-curl sqlite3 php-sqlite3 -y
Using wget, the source code for the LXD dashboard can be downloaded from the GitHub repository. For this guide the v2.2.0 release will be used. Check for newer versions on the GitHub page and replace the version number with the latest. To download and extract the source code use the following two commands:
$ wget https://github.com/lxdware/lxd-dashboard/archive/v2.2.0.tar.gz $ tar -xzf v2.2.0.tar.gz
A few web server files will need to moved into place for the web pages as well as the NGINX configuration. To copy these files use the following commands, making sure to change the version number to what was downloaded:
$ cp -a lxd-dashboard-2.2.0/default /etc/nginx/sites-available/ $ cp -a lxd-dashboard-2.2.0/lxd-dashboard /var/www/html/
There are three main directories that LXDWARE uses to store persistent information for the application. You will need to create these directories and then assign appropriate ownership to the web server. To create the directories use the following commands:
$ mkdir -p /var/lxdware/data/sqlite $ mkdir -p /var/lxdware/data/lxd $ mkdir -p /var/lxdware/backups
The /var/www/html/lxd-dashboard/ directory, the /var/lxdware/ directory, and the contents within them all need to be owned by the web server user. To set the proper permissions run the following commands:
$ chown -R www-data:www-data /var/lxdware/ $ chown -R www-data:www-data /var/www/html
The NGINX web server will need to be restarted to apply the web server configuration changes made above. To restart the web server run the following command:
$ systemctl restart nginx
Congratulations! The container is now setup with the LXD dashboard software. Exit from the bash terminal and return to your LXD host server by using the command:
Open a web browser and access the LXD dashboard by entering in the IP address of the instance. Use the lxc list command to view a list of the containers and their IP addresses on your LXD server.
Optional Port Forward Configuration
Port forwarding can be used to make the lxd-dashboard instance accessible to others computers outside of the server. The lxd-dashboard listens on port 80 for web traffic. In this how-to guide the host’s port 80 will be forwarded to the instance’s port 80. For more information on port forwarding view the how-to guide Forwarding host ports to LXD instances.
To create a new profile named proxy-port-80 use the following command:
$ lxc profile create proxy-port-80
To configure the profile to forward the port 80 from the host server to port 80 on the instance, use the following command:
$ lxc profile device add proxy-port-80 hostport80 proxy connect="tcp:127.0.0.1:8080" listen="tcp:0.0.0.0:80"
To apply the newly created profile to the lxd-dashboard instance and begin forwarding port 80 traffic to your instance run the following command:
$ lxc profile add lxd-dashboard proxy-port-80
Open a web browser and access the LXD dashboard by entering in the IP address of the host server.