LXD (Linux Containers) for Nextcloud

LXD is a next generation system container manager. It offers a user experience similar to virtual machines but using Linux containers instead. LXD isn’t a rewrite of LXC, in fact it’s building on top of LXC to provide a new, better user experience. Under the hood, LXD uses LXC through liblxc and its Go binding to create and manage the containers. It’s basically an alternative to LXC’s tools and distribution template system with the added features that come from being controllable over the network.

And your are only four steps away from your LXD environment running your Nextcloud instance virtualized.

  1. First – install lxd on your Ubuntu OS
  2. Second – setup and configure LXD (LAN and storage)
  3. Third – create your Nextcloud container (Ubuntu 18.04)
  4. Fourth – launch the container and install Nextcloud using the shell script

(1) First install lxd on your Ubuntu OS

Update your environment and install lxd

sudo -s
apt update && apt upgrade -y && apt install lxd -y

Add your operating user to the lxd group

adduser <username> lxd

To apply these changes issue

newgrp lxd

or restart your ssh session. Verify your changes by issuing


as your normal user. Your users membership should consist of 999(lxd).

(2) Setup and configure LXD (LAN and storage)

(Optionally) You may install ZFS what offers more and quick options for creating snapshots and other features.

sudo -s
apt install zfsutils-linux -y

Configure your LXD

lxd init

To operate with LXD as a normal user modify two files:

sudo vi /etc/subuid
sudo vi /etc/subgid

and add


From now your LXD is configured properly and you can find e.g. Ubuntu images by issuing

lxc image list images: | grep -i ubuntu

(3) Create your Nextcloud container (Ubuntu 18.04)

To launch your first Ubuntu 18.04 container issue

lxc launch images:ubuntu/bionic/amd64 crieger

(4) Launch the container and install Nextcloud using the shell script

If created just connect to that container by issuing

lxc exec crieger bash

Finally build your Nextcloud server using my installer script.

apt install git -y
cd /usr/local/src
git clone https://github.com/riegercloud/install-nextcloud.git cd install-nextcloud
chmod +x *.sh

Wait a few minutes … fill in few parameters …

and you will enjoy your new Nextcloud (test-)environment

in your preferred Browser using the IP or DNS. It might become necessary to amend Nextclouds trusted urls by issuing

sudo -u www-data php /var/www/nextcloud/occ config:system:set trusted_domains 1 --value=<LXD Container-IP>

Enjoy your Nextcloud within your own LXD container.

Useful LXD things:

START: lxc start container-name

lxc start crieger

STOP: lxc stop container-name

lxc stop crieger

DELETE: lxc delete container-name

lxc delete crieger

INFORMATION: lxc info container-name

lxc info crieger

Find out more: here

Enjoy your personal data in your secured and hardened Nextcloud-Server!

Don’t forget to backup your Nextcloud

Find more instructions here: Nextcloud backup and restore

Carsten Rieger

Carsten Rieger

Carsten Rieger is a senior system engineer in full-time and also working as an IT freelancer. He is working with linux environments for more than 13 years, an Open Source enthusiast and highly motivated on linux installation and troubleshooting. Mostly working with Debian/Ubuntu Linux, Nginx and Apache web server, MariaDB/MySQL/PostgreSQL, PHP, Cloud infrastructure (e.g. Nextcloud) and other open source projects (e.g. Roundcube) and in voluntary work for the Dr. Michael & Angela Jacobi Stiftung for more than 7 years.