Nextcloud is a popular open-source file-sharing platform that can be self-hosted on your own server. Docker is a containerization technology that makes it easy to deploy and manage Nextcloud in a container. In this tutorial, we'll walk through the process of installing Nextcloud usint the Apache Docker image, opening the correct UFW ports, and configuring the trusted domains in the config.php file for use with a public IP.
Prerequisites
Before we begin, ensure that you have the following:
- A Debian or Ubuntu based distribution of Linux
- A Debian or Ubuntu based distribution of Linux
- Docker installed
Install Nextcloud Using Docker
To install Nextcloud using the Apache Docker image, we'll use the official Nextcloud Docker image available on Docker Hub. (Note: You must be Root or Sudo to use Docker commands.) Here are the steps: 1. Pull the official Nextcloud image from Docker Hub:
$
docker pull nextcloud
2. Start the container with the following command:
$
docker run -d -p 8080:80 nextcloud
This command starts the Nextcloud container and maps port 8080 on the host to port 80 in the container. You should now be able to access docker at http://localhost:8080/ from your host system.
3. Verify that the container is running:
$
docker ps
You have now successfully installed Nextcloud using the Apache Docker image. Note your container ID number and name in the output as I will be referring to it as <container-ID> going forward. You will still need to open the following ports to be able to access NextCloud from other devices other than your host system or to access it from your host system using your public IP address.
Opening UFW Ports
To allow incoming traffic to your Nextcloud instance, we need to open the correct ports in UFW. Here are the steps: 1. Allow incoming HTTP traffic:
$
ufw allow 8080
$ ufw allow 80
$ ufw allow 443
2. Reload UFW: $
ufw reload
Opening Bash in the Docker Container
To open a Bash shell inside the Docker container, use the following command:
$
docker exec -it <container-id> bash
Updating the Container
Before you can edit the config.php file, you need to update
the container to be able to install nano (a text editor). Use the
following command to update the container:
$
Add the public IP address to the
Save and exit the file.
Congratulations! You have now successfully configured Nextcloud to use
a public IP address. You can access your Nextcloud instance by navigating to http://your_public_ip_address in your web browser.
apt-get update && apt-get install nano
Editing the config.php File
To configure Nextcloud to use a public IP address, we need to add the public IP address to the config.php file. (Note: the config file won't be available until after you open Docker for the first time and setup your Admin account.) Here are the steps:
$
cd /var/www/html/config/
$
nano config.php
Add the public IP address to the
trusted_domains
array:'trusted_domains' =>
array (
0 => 'localhost:8080',
1 => 'your_public_ip_address',
),
Note: Be sure to replace your_public_ip_address with your own public IP address. Save and exit the file.
Congratulations! You have now successfully configured Nextcloud to use
a public IP address. You can access your Nextcloud instance by navigating to http://your_public_ip_address in your web browser.