How to Install Nextcloud with Docker and Docker Compose on Ubuntu

How to Install Nextcloud with Docker and Docker Compose on Ubuntu

Nextcloud is a popular open-source platform that enables users to host their own cloud storage, offering functionality similar to services like Google Drive or Dropbox. Installing Nextcloud with Docker and Docker Compose on an Ubuntu server offers a flexible and straightforward approach to managing your cloud storage solution. This guide will walk you through the process step-by-step.

Prerequisites

Before starting, ensure your system meets the following requirements:

  1. Ubuntu Server: This guide assumes you’re using Ubuntu 20.04 or later.
  2. User with Sudo Privileges: You’ll need administrative access to perform installations and configuration.
  3. Basic Knowledge of Linux: Familiarity with basic Linux commands will be helpful.

Step 1: Update Your System

The first step in setting up Nextcloud is to update your Ubuntu server to ensure all packages are current.

sudo apt update && sudo apt upgrade -y

 

This command updates the package list and upgrades all installed packages to the latest versions.

Step 2: Set Up Nextcloud with Docker Compose

With Docker and Docker Compose installed, you’re ready to set up Nextcloud.

Create a Docker Compose File

Start by creating a directory for your Nextcloud setup:

mkdir ~/nextcloud
cd ~/nextcloud

 

Next, create a docker-compose.yml file in this directory:

nano docker-compose.yml

 

Copy and paste the following content into the file:

version: '3.7'

networks:
default:
name: monitoring-net
external: true

volumes:
nextcloud:
db:

services:
db:
image: mariadb
restart: always
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
volumes:
- ./db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=asdqwe123
- MYSQL_PASSWORD=next123
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud

app:
image: nextcloud:production
restart: always
ports:
- 8086:80
links:
- db
volumes:
- ./nextcloud:/var/www/html
environment:
- MYSQL_PASSWORD=next123
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_HOST=db
- NEXTCLOUD_TRUSTED_DOMAINS="nextcloud.linuxcodelab.eu 78.128.88.290 10.10.10.110"
- TRUSTED_PROXIES=nginx-pm nextcloud.eu
- OVERWRITEPROTOCOL=https
- OVERWRITECLIURL=nextcloud.linuxcodelab.eu

In this configuration:

  • The nextcloud service uses the official Nextcloud image and maps port 8080 on your host to port 80 in the container.
  • The db service uses the official MariaDB image as the database for Nextcloud. Replace example_root_password and example_password with strong passwords.

Start the Nextcloud Stack

To start your Nextcloud and MariaDB containers, run:

sudo docker-compose up -d

 

The -d flag tells Docker Compose to run the containers in detached mode, allowing them to run in the background.

Check Running Containers

Verify that the containers are running correctly:

sudo docker ps

 

You should see entries for both nextcloud and db containers.

Step 3: Configure Nextcloud

Now that your containers are running, you need to configure Nextcloud.

Access Nextcloud via Web Browser

Open a web browser and navigate to http://<your_server_ip>:8086. You should see the Nextcloud setup page.

Complete the Installation

  1. Create an Admin Account: Enter your desired admin username and password.
  2. Database Configuration: Under the “Database” section:
    • Database user: nextcloud
    • Password: Use the password you set in the docker-compose.yml file.
    • Database name: nextcloud
    • Database host: db (use this hostname as specified in the docker-compose.yml file)
  3. Finish Setup: Click “Finish Setup” to complete the installation. Nextcloud will finalize its configuration and redirect you to the login page.

Step 6: Secure Your Nextcloud Installation

Securing your Nextcloud installation is crucial to protect your data.

Set Up HTTPS

It’s recommended to use HTTPS to encrypt your traffic. You can set up an Nginx reverse proxy with Let’s Encrypt to achieve this. This guide won’t cover the full process, but it involves:

  1. Installing Nginx.
  2. Configuring Nginx as a reverse proxy for your Nextcloud instance.
  3. Obtaining a Let’s Encrypt SSL certificate and configuring Nginx to use it.

Regular Backups

Ensure you have a regular backup strategy for your Nextcloud data and MariaDB database. Docker volumes can be backed up using commands like docker cp or by using a backup container.

Keep Software Updated

Regularly update Docker, Docker Compose, and Nextcloud to ensure you have the latest security patches and features.

Conclusion

By following this guide, you’ve installed and configured Nextcloud using Docker and Docker Compose on Ubuntu. This setup allows you to host your own cloud storage solution with the flexibility and isolation that Docker provides. Regularly maintain and secure your installation to keep your data safe and ensure smooth operation.

With this powerful setup, you’re now ready to explore the full potential of Nextcloud, whether for personal use or collaboration within a team. Enjoy your self-hosted cloud!

Fedya Serafiev

Fedya Serafiev

Fedya Serafiev owns the website linuxcodelab.eu. He finds satisfaction in helping people solve even the most complex technical problems. His current goal is to write easy-to-follow articles so that such problems do not arise at all.

Thank you for reading the article! If you found the information useful, you can donate using the buttons below: