# How to use Nextcloud file syncing with Meshnet

## Introduction <a href="#introduction" id="introduction"></a>

[Nextcloud ](https://nextcloud.com/about/)is a free and open-source online collaboration platform. It offers a wide range of tools and applications, such as file sharing and synchronization, calendar, tasks, and workflow integrations. Nextcloud is scalable from personal use to enterprise-level environments.

In standard configurations, to share your Nextcloud servers with remote devices, you must set up public domain names and SSL certificates or port forwarding, which can be both expensive and time-consuming.

With [Meshnet](https://nordvpn.com/meshnet/), you can forget about the difficult networking procedures. With only a couple of tweaks to the Nextcloud configuration, your Meshnet peer devices can access the server over encrypted, private network tunnels without exposing Nextcloud to the internet.

While Nextcloud can be set up using various methods, such as a [virtual machine](https://github.com/nextcloud/vm) or a [standalone operating system](https://github.com/nextcloud/nextcloudpi/releases), this article will show you how to run Nextcloud in a [Docker container](https://www.docker.com/resources/what-container/) and access it over Meshnet.

## Install Docker <a href="#install-docker" id="install-docker"></a>

To begin the configuration, you must have Docker installed on your device. Instructions on how to download and install Docker can be found on the Docker website:

* [Docker Desktop instructions for Windows](https://docs.docker.com/desktop/install/windows-install/)
* [Docker Desktop instructions for macOS](https://docs.docker.com/desktop/install/mac-install/)
* [Docker Desktop Instructions for Linux (application with a GUI)](https://docs.docker.com/desktop/install/linux-install/)
* [Docker Engine instructions for Linux (CLI only)](https://docs.docker.com/engine/install/)

## Create a Nextcloud Docker container <a href="#create-a-nextcloud-docker-container" id="create-a-nextcloud-docker-container"></a>

After installing Docker on your system, you have the ability to deploy various applications and services as Docker containers. Now you can proceed with creating your Nextcloud container.

### Creating a volume <a href="#creating-a-volume" id="creating-a-volume"></a>

First, you need to create a specific [Docker volume](https://docs.docker.com/storage/volumes/) (directory) where the container’s files will be stored.

#### Method 1: Using Docker Desktop <a href="#method-1-using-docker-desktop" id="method-1-using-docker-desktop"></a>

This method utilizes the Docker Desktop application to create a volume for the Nextcloud Docker container.

1. Open the Docker Desktop application.

2. From the menu on the left, select **Volumes**.<br>

   <div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FiT3GV9EU02F2TTORybm8%2Fha_docker_volumes.png?alt=media&#x26;token=d7a772c4-be31-42ff-a83a-04d09e89d02b" alt="Docker Desktop application"><figcaption></figcaption></figure></div>

3. Click the **Create** button in the upper-right corner.

4. Name it `nextcloud` and click **Create**.\
   &#x20;

   ![Docker Desktop new volume](https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2F5EGScFSVG58HB6g0Qj7o%2Fdocker_volume_create.png?alt=media\&token=8d111c05-cd49-40ae-bd35-e1f7a4abb9be)

   &#x20;

5. The newly created volume will now be visible in the **Volumes** section.

#### Method 2: Using the command line <a href="#method-2-using-the-command-line" id="method-2-using-the-command-line"></a>

This method shows you how to create a volume for your Nextcloud Docker container via the command line.

1. Open **Command Prompt** (on Windows) or **Terminal** (on Linux or macOS).
2. Run the following command to create a volume called `nextcloud`:<br>

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">docker volume create nextcloud
   </code></pre>

If the creation was successful, you will see the name of your volume in the command line window.

### Deploying a container <a href="#deploying-a-container" id="deploying-a-container"></a>

Once the volume has been created, you can deploy the Nextcloud container itself.

{% tabs %}
{% tab title="Windows" %}

1. Open **Command Prompt**.
2. Execute the following `docker run` command:<br>

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">docker run -d ^
   --name nextcloud ^
   --restart=unless-stopped ^
   -p 8080:80 ^
   -v nextcloud:/var/www/html ^
   nextcloud
   </code></pre>

Docker will [pull the Nextcloud image](https://docs.docker.com/engine/reference/commandline/pull/) from Docker Hub and create the container.
{% endtab %}

{% tab title="macOS and Linux" %}

1. Open **Terminal**.
2. Execute the following `docker run` command:<br>

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">docker run -d \
   --name nextcloud \
   --restart=unless-stopped \
   -p 8080:80 \
   -v nextcloud:/var/www/html \
   nextcloud
   </code></pre>

Docker will [pull the Nextcloud image](https://docs.docker.com/engine/reference/commandline/pull/) from Docker Hub and create the container.
{% endtab %}
{% endtabs %}

## Set up Nextcloud <a href="#set-up-nextcloud" id="set-up-nextcloud"></a>

With the container up and running, your Nextcloud service is listening on port 8080 (unless changed in the `docker run` command). To complete the initial configuration, do the following:

1. Open your internet browser and visit this URL:\
   `http://localhost:8080/`<br>
2. Enter authentication details for your admin account, select the preferred database, and click **Install**.\
   \
   ![Nextcloud admin account creation](https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FqdzprrQzQmtrZUHDlxzX%2Fnc_create_admin.png?alt=media\&token=18475461-2815-49e0-9a9b-82497c42d057)

   &#x20;
3. Finish the setup procedure by following the on-screen instructions.

Now, you have a fully customizable Nextcloud instance.

<figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FdpqzU6quA7lYTFu99DNO%2Fnc_dashboard.png?alt=media&#x26;token=fc3a3c6d-8f97-49e1-91a6-667a578fb3f4" alt="Nextcloud dashboard"><figcaption></figcaption></figure>

## Allow Meshnet connections <a href="#allow-meshnet-connections" id="allow-meshnet-connections"></a>

At this time, Nextcloud is only reachable from the host device. You need to adjust its configuration file to allow connections over Meshnet.

### Method 1: Using Docker Desktop <a href="#method-1-using-docker-desktop.1" id="method-1-using-docker-desktop.1"></a>

This method uses the built-in terminal in Docker Desktop to make changes.

1. Open Docker Desktop and click your Nextcloud container entry.

2. Switch to the **Terminal** tab.

3. Run the following command to update the repository list, install Nano, and open the `config.php` file using Nano:<br>

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">apt update &#x26;&#x26; apt install nano &#x26;&#x26; nano config/config.php
   </code></pre>

   &#x20;

4. Locate the `trusted_domains` array and append the following two lines, where `<NordName>` is the host device’s Nord name and `<MeshnetIP>` is the host device’s Meshnet IP address:<br>

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">1 => '&#x3C;NordName>',
   2 => '&#x3C;MeshnetIP>',
   </code></pre>

   \
   **Example**

   <div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2Fd79r0zlAP6ARAJwqRFKl%2Fnc_trusted_dd.png?alt=media&#x26;token=7f7f7579-b7c6-46e1-a49a-c80f895602f7" alt="Nord name and Meshnet IP address added to the &#x27;trusted domains&#x27; array"><figcaption></figcaption></figure></div>

5. Press **Ctrl** + **X**, **Y**, and **Enter** to save changes and exit.

6. Restart the Nextcloud container to apply the changes by clicking the restart button in Docker Desktop.<br>

   <div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2F5iRuYv4o7DaCTLVYpeJg%2Fnc_restart_dd.png?alt=media&#x26;token=f718b1b1-66b2-4115-b213-a30cd9933883" alt=""><figcaption></figcaption></figure></div>

### Method 2: Using the command line <a href="#method-2-using-the-command-line.1" id="method-2-using-the-command-line.1"></a>

This method uses Nextcloud’s built-in command-line interface called `occ`.

1. Open **Command Prompt** (on Windows) or **Terminal** (on Linux or macOS).

2. Add new trusted domains by executing the following two commands, where `<NordName>` is the host device’s Nord name and `<MeshnetIP>` is the host device’s Meshnet IP address:<br>

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">docker exec -u www-data -it nextcloud php occ config:system:set trusted_domains 1 --value=&#x3C;NordName>

   docker exec -u www-data -it nextcloud php occ config:system:set trusted_domains 2 --value=&#x3C;MeshnetIP>
   </code></pre>

   \
   **Example**

   <div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FolyCuSo79W8wPbxHhCGb%2Fnc_docker_exec.png?alt=media&#x26;token=69647bc9-8027-4623-b5c6-f01d10164b87" alt="Adding trusted domains using occ"><figcaption></figcaption></figure></div>

3. Check if the Nord name and Meshnet IP address have been assigned by running this command:<br>

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">docker exec -u www-data -it nextcloud php occ config:system:get trusted_domains
   </code></pre>

   &#x20;

   <div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FICNOzMdHcRrzqFRMxcew%2Fnc_docker_exec_domains.png?alt=media&#x26;token=55c0b052-c07f-4fa8-b895-0e3c74e2a6e9" alt="List of trusted domains"><figcaption></figcaption></figure></div>

4. Restart the Nextcloud container to apply the changes.

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">docker restart nextcloud
   </code></pre>

## Connect to Nextcloud over Meshnet <a href="#connect-to-nextcloud-over-meshnet" id="connect-to-nextcloud-over-meshnet"></a>

After adding the Meshnet addresses to the trusted domains, your Nextcloud instance can be reached by Meshnet peer devices.

{% hint style="info" %}
**Note**

If you're hosting Nextcloud on a Linux device, you must grant the [local network permission](https://meshnet.nordvpn.com/features/explaining-permissions/local-network-permissions) for the devices accessing it. For more information, see [Common issues on Linux](https://meshnet.nordvpn.com/troubleshooting/linux#cannot-access-docker-containers-over-meshnet).
{% endhint %}

### Method 1: Using Nextcloud software <a href="#method-1-using-nextcloud-software" id="method-1-using-nextcloud-software"></a>

To use file syncing between different machines, you need to install the Nextcloud application on client devices.

{% hint style="info" %}
**Note**

Folder synchronization is possible only on desktop devices. On mobile devices, you can only upload and download files manually.
{% endhint %}

{% tabs %}
{% tab title="Windows, macOS, and Linux" %}

1. Download and install the Nextcloud application from the [Nextcloud website](https://nextcloud.com/install/).
2. Launch Nextcloud and click **Log in**.
3. In the server address field, enter `http://`, followed by the Nord name of the host device, and `:8080`.<br>

   **Example**\
   `http://secret.meerkat-himalayas.nord:8080`\
   \
   ![Nextcloud application window](https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FOq08FBMBaUZr4fti1iKI%2Fnc_server_address.png?alt=media\&token=0fda271c-c7aa-4a55-89ae-1f5090315ae9)

   &#x20;
4. Click **Next** and proceed with the login procedure.
5. Select your folder synchronization options and click **Connect**.\
   \
   ![Folder synchronization window](https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FEqB2Du0coIyMwCjXmkoL%2Fnc_folder_sync.png?alt=media\&token=64659b1a-26ff-4f47-a0f6-e7735103dd64)

   &#x20;

Nextcloud settings can now be accessed from the system tray (on Windows) and the menu bar (on macOS or Linux).

{% hint style="success" %}
**Tip**

For ease of use, you may download the Nextcloud application from the [Snap Store](https://snapcraft.io/nextcloud) on compatible Linux distributions.
{% endhint %}
{% endtab %}

{% tab title="Android and iOS" %}

1. Download and install the Nextcloud application on your device.
   * [For Android](https://play.google.com/store/apps/details?id=com.nextcloud.client\&hl=en\&gl=US)
   * [For iOS](https://apps.apple.com/us/app/nextcloud/id1125420102)
2. Open Nextcloud and tap **Log in**.
3. In the server address field, enter `http://`, followed by the Nord name of the host device and `:8080`.<br>

   **Example**\
   `http://secret.meerkat-himalayas.nord:8080`\
   \
   ![Nextcloud application window](https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FbmFvtfd7u791c1dBozHs%2Fnc_login_mobile.png?alt=media\&token=2bccc950-0d6a-4cc5-b352-11b5645a0e78)

   &#x20;
4. Log in to your Nextcloud account.

Now you have full access to the Nextcloud interface directly from the application.
{% endtab %}
{% endtabs %}

### Method 2: Using an internet browser <a href="#method-2-using-an-internet-browser" id="method-2-using-an-internet-browser"></a>

To access the Nextcloud dashboard via a browser, do these steps:

1. Copy the Nord name of the host device from the NordVPN application.

2. Open your internet browser.

3. Paste the copied Nord name followed by `:8080/` to the URL field and press **Enter**.\
   \
   **Example**\
   `secret.meerkat-everest.nord:8080/`<br>

   <div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2Fk8ujnhI9R9QGEXtG0ZRC%2Fnc_remote_dash.png?alt=media&#x26;token=7190ee5b-e1e1-437d-b525-6d6c53bfac66" alt="Nextcloud login page"><figcaption></figcaption></figure></div>

4. Log in to your account.

Now you can freely navigate your Nextcloud from a remote device. You can view, upload, or remove files and use all other applications inside Nextcloud.

<div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2F4ZjaZBmwMnZLSjl416Go%2Fnc_remote_files.png?alt=media&#x26;token=08dbd8fa-152b-428a-9f37-20145c2db9ec" alt="Nextcloud file list"><figcaption></figcaption></figure></div>
