How to migrate your NCP docker container to LXD
Disclaimer: This guide assumes, that you are using NCP >= 1.51.2. If you are on an earlier version, please upgrade first.
1. Setup LXD
Upstream Guide: Linux Containers - LXD - Getting started
- Install snap. The following commands work on Debian based systems, for other linux distributions refer to the LXD documentation
sudo apt install snapd sudo snap install core sudo snap install lxd
- If you require docker on your server and experience connectivity issues along the way (I didn’t in my tests), follow these instructions
2. Create backup of your docker instance
- Use the admin web panel of your NCP docker instance to create a backup and choose a target location in a directory that has been mounted from the host into the container (the default target directory is probably fine)
- If you didn’t choose to include data in your backup, make sure you find your data directory on the host (recognized by the file
.ocdata
that it contains at root level).
3. Setup an NCP lxd container
-
Make sure, your ncp docker container is stopped and ports 80 and 443 are not blocked on the host
-
Download the NCP LXD image for your architecture that corresponds to the NCP version that you had running in docker from Releases · nextcloud/nextcloudpi · GitHub, e.g.:
wget https://github.com/nextcloud/nextcloudpi/releases/download/v1.51.0/NextCloudPi_LXD_v1.51.0.tar.gz
-
Import the downloaded image, e.g.:
lxc image import NextCloudPi_LXD_v1.51.0.tar.gz --alias ncp/v1.51.0
-
(Optional) Create a new lxd storage pool for your data. This can be used to store the data on a specific disk and also for creating snapshots later on (using LXD’s builtin tools).
- If you have a btrfs partition that should (entirely) be used by lxd, use the btrfs driver:
lxc storage create ncp btrfs source=/mnt/your-disk
- Otherwise, use another compatible storage driver, e.g. the
dir
driver:lxc storage create ncp dir source=/storage/pool/directory
- Finally, create a storage volume:
lxc storage volume create ncp ncpdata
- If you have a btrfs partition that should (entirely) be used by lxd, use the btrfs driver:
-
Create a new lxd container:
lxc launch ncp/v1.51.0 nextcloudpi
ncp/v1.51.0
is the alias that you chose when importing the image (step 2)
nextcloudpi
is the container name -
(Skip if you skipped 4.) Wait a few seconds to let ncp initialize then move the data directory out of the way and mount a storage volume to use for your data, then move the data directory back.
this step requires that your lxd container is updated to v1.51.2 or later- Move your data directory to
/var/ncdata
usingnc-datadir
from the web UI or fromncp-config
. - Run the following command to attach your storage volume:
lxc storage volume attach ncp ncpdata nextcloudpi /opt
- Move the data directory back to
/opt/ncdata
usingnc-datadir
from the web UI or fromncp-config
.
- Move your data directory to
-
Forward ports 80 and 443 from your host system to the lxd container (alternatively, you can use a reverse proxy, this is not covered in this guide)
lxc config device add nextcloudpi proxy443 proxy connect="tcp:127.0.0.1:443" listen="tcp:0.0.0.0:443" lxc config device add nextcloudpi proxy80 proxy connect="tcp:127.0.0.1:80" listen="tcp:0.0.0.0:80"
-
Find the ip adress using
lxc info nextcloudpi
(where ‘nextcloudpi’ is the container name). Then access the NCP activation page directly using this IP (on the same host), e.g. https://10.124.228.246, and activate NCP -
You should now be able to access Nextcloud at your server’s IP address
4. Restore your backup in the lxd container
The following steps assume that the directory that was mounted into your docker container is located at /mnt/ncp-docker
on the host - i.e. that your docker run command was:
docker run -d -p 4443:4443 -p 443:443 -p 80:80 -v /mnt/ncp-docker:/data --name nextcloudpi ownyourbits/nextcloudpi:v1.51.0 <your-domain>
IF YOU HAVE A BACKUP INCLUDING DATA, SKIP STEPS 1-2
-
Push your data directory to your lxd container:
lxc file push -r /mnt/ncp-docker/ncdata/data nextcloudpi/opt/ncdata/
-
Fix filesystem permissions on the lxd container using
nc-fix-permissions
from the admin web interface orncp-config
You can run
ncp-config
like this:lxc exec nextcloudpi -- ncp-config
(Press Ctrl+C if nothing happens when executing this command - then you will be able to navigate the cli)
-
Apply a quick fix to ensure compatibility between your lxd container and the docker backup:
lxc exec nextcloudpi -- ln -s /opt /data
-
Push your backup file to the container, e.g.:
lxc file push /mnt/ncp-docker/backups/ncp-backups/nextcloud-bkp_20230328_1680021512.tar.gz nextcloudpi/ncp-backup.tar.gz
where ‘nextcloudpi’ is the name of your lxd container
-
Restore the backup with the following command:
lxc exec nextcloudpi -- ncp-restore /ncp-backup.tar.gz