Guide to migrate your NCP instance from Docker to LXD

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

  1. 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
  2. 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

Relevant documentation

  1. 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)
  2. 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

  1. Make sure, your ncp docker container is stopped and ports 80 and 443 are not blocked on the host

  2. 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.:

  3. Import the downloaded image, e.g.:

    lxc image import NextCloudPi_LXD_v1.51.0.tar.gz --alias ncp/v1.51.0
  4. (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
  5. 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

  6. (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

    1. Move your data directory to /var/ncdata using nc-datadir from the web UI or from ncp-config.
    2. Run the following command to attach your storage volume:
    lxc storage volume attach ncp ncpdata nextcloudpi /opt
    1. Move the data directory back to /opt/ncdata using nc-datadir from the web UI or from ncp-config.
  7. 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:" listen="tcp:"
    lxc config device add nextcloudpi proxy80 proxy connect="tcp:" listen="tcp:"
  8. 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., and activate NCP

  9. 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>


  1. Push your data directory to your lxd container:

    lxc file push -r /mnt/ncp-docker/ncdata/data nextcloudpi/opt/ncdata/
  2. Fix filesystem permissions on the lxd container using nc-fix-permissions from the admin web interface or ncp-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)

  3. Apply a quick fix to ensure compatibility between your lxd container and the docker backup:

    lxc exec nextcloudpi -- ln -s /opt /data
  4. 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

  5. Restore the backup with the following command:

    lxc exec nextcloudpi -- ncp-restore /ncp-backup.tar.gz

Hey there, right now the current docker version is 1.51.4. There is no corresponding LXD version (the release in the same timeframe is 1.52.0).

How would we go about migrating if we are on 1.51.4?

2 posts were split to a new topic: Struggling to setup LXD based NCP on Step 6.2

Hey, sorry for the late reply - unfortunately, I missed your message.

For future reference: You can use the LXD image v1.52.0 to migrate from any v1.51.X docker image.


3 posts were split to a new topic: No data-folder option migrating from Docker to LXD