Nextcloud Docker Compose Installation Guide

Author

Reads 136

Modern data center corridor with server racks and computer equipment. Ideal for technology and IT concepts.
Credit: pexels.com, Modern data center corridor with server racks and computer equipment. Ideal for technology and IT concepts.

Let's get started with installing Nextcloud using Docker Compose. First, make sure you have Docker and Docker Compose installed on your system.

Docker Compose is a tool for defining and running multi-container Docker applications. We'll use it to create a Nextcloud container.

To begin, create a new directory for your Nextcloud project and navigate to it in your terminal. This will be the root directory for our Docker Compose project.

Next, create a new file called `docker-compose.yml` in this directory. This file will contain the configuration for our Nextcloud container.

Database and Storage

By default, this Nextcloud container uses SQLite for data storage, but you can connect to an existing MySQL/MariaDB or PostgreSQL database via the Nextcloud setup wizard.

To enable auto configuration, define your database connection via environment variables. You can specify all of the environment variables for a given database, or the database environment variables will default to SQLite. ONLY use one database type!

Credit: youtube.com, Make Nextcloud Using Docker-Compose in 5 Min

Here's a list of the environment variables you can use to configure your database:

  • For SQLite: SQLITE_DATABASE (Name of the database using sqlite)
  • For MYSQL/MariaDB: MYSQL_DATABASE (Name of the database using mysql / mariadb), MYSQL_USER (Username for the database using mysql / mariadb), MYSQL_PASSWORD (Password for the database user using mysql / mariadb), MYSQL_HOST (Hostname of the database server using mysql / mariadb)
  • For PostgreSQL: POSTGRES_DB (Name of the database using postgres), POSTGRES_USER (Username for the database using postgres), POSTGRES_PASSWORD (Password for the database user using postgres), POSTGRES_HOST (Hostname of the database server using postgres)

Nextcloud also allows the use of object storages (like OpenStack Swift or any Amazon S3-compatible implementation) as Primary Storage. You can set the following variables to use an external S3 compatible object store as primary storage:

  • OBJECTSTORE_S3_BUCKET (The name of the bucket that Nextcloud should store the data in)
  • OBJECTSTORE_S3_REGION (The region that the S3 bucket resides in)
  • OBJECTSTORE_S3_HOST (The hostname of the object storage server)
  • OBJECTSTORE_S3_PORT (The port that the object storage server is being served over)
  • OBJECTSTORE_S3_KEY (AWS style access key)
  • OBJECTSTORE_S3_SECRET (AWS style secret access key)
  • OBJECTSTORE_S3_STORAGE_CLASS (The storage class to use when adding objects to the bucket)
  • OBJECTSTORE_S3_SSL (Whether or not SSL/TLS should be used to communicate with object storage server)
  • OBJECTSTORE_S3_USEPATH_STYLE (Whether or not to use path style for the object storage server)
  • OBJECTSTORE_S3_LEGACYAUTH (Whether or not to use legacy authentication for the object storage server)
  • OBJECTSTORE_S3_OBJECT_PREFIX (Prefix to prepend to the fileid)
  • OBJECTSTORE_S3_AUTOCREATE (Whether or not Nextcloud should automatically create the container)
  • OBJECTSTORE_S3_SSE_C_KEY (Base64 encoded key with a maximum length of 32 bytes for server side encryption (SSE-C))

External Database

You can use an external database with Nextcloud, but it requires some setup. By default, Nextcloud uses SQLite for data storage, but you can connect to an existing MySQL/MariaDB or PostgreSQL database.

The Nextcloud setup wizard allows you to connect to an existing database on first run. You can also link a database container, for example, `--link my-mysql:mysql`, and then use `mysql` as the database host on setup.

To enable auto configuration, define your database connection via environment variables. If you set any group of values, they will not be requested via the Installation Wizard on first run.

Here are the environment variables you need to specify for each database type:

You must specify all of the environment variables for a given database, or the database environment variables will default to SQLite. Only use one database type!

Object Storage

Credit: youtube.com, What is Object Storage?

Nextcloud allows you to use object storages as primary storage, which can be a game-changer for large file storage needs.

Object storage is a type of storage that stores data across a cluster of servers, making it highly scalable and fault-tolerant. Nextcloud supports object storages like OpenStack Swift and Amazon S3-compatible implementations.

To use an external S3-compatible object store as primary storage, you need to set several variables in Nextcloud. These variables include OBJECTSTORE_S3_BUCKET, OBJECTSTORE_S3_REGION, OBJECTSTORE_S3_HOST, OBJECTSTORE_S3_PORT, OBJECTSTORE_S3_KEY, and OBJECTSTORE_S3_SECRET.

Here are the variables you need to set for an external S3-compatible object store:

For OpenStack Swift, you need to set variables like OBJECTSTORE_SWIFT_URL, OBJECTSTORE_SWIFT_AUTOCREATE, OBJECTSTORE_SWIFT_USER_NAME, and OBJECTSTORE_SWIFT_USER_PASSWORD.

Credit: youtube.com, Data Storage Types: File, Block, & Object

Here are the variables you need to set for an external OpenStack Swift object store:

  • OBJECTSTORE_SWIFT_URL: The Swift identity (Keystone) endpoint
  • OBJECTSTORE_SWIFT_AUTOCREATE (default: false): Whether or not Nextcloud should automatically create the Swift container
  • OBJECTSTORE_SWIFT_USER_NAME: Swift username
  • OBJECTSTORE_SWIFT_USER_PASSWORD: Swift user password
  • OBJECTSTORE_SWIFT_USER_DOMAIN (default: Default): Swift user domain
  • OBJECTSTORE_SWIFT_PROJECT_NAME: OpenStack project name
  • OBJECTSTORE_SWIFT_PROJECT_DOMAIN (default: Default): OpenStack project domain
  • OBJECTSTORE_SWIFT_SERVICE_NAME (default: swift): Swift service name
  • OBJECTSTORE_SWIFT_REGION: Swift endpoint region
  • OBJECTSTORE_SWIFT_CONTAINER_NAME: Swift container (bucket) that Nextcloud should store the data in

SSL Encryption

SSL encryption is essential for securing your Nextcloud installation. HTTPS is the recommended protocol, and you can use a reverse proxy to encrypt all traffic to clients.

A reverse proxy in front of your Nextcloud installation is the recommended setup. Your Nextcloud will only be reachable through the proxy, which encrypts all traffic to the clients.

You can mount your manually generated certificates to the proxy or use a fully automated solution. A fully automated setup using a reverse proxy and Let's Encrypt certificate handling is available in our examples section.

The popular nginx-proxy and acme-companion containers are used in this setup. Please check the according documentations before using this setup, as it's a complex configuration.

Take a look at this: Nextcloud Reverse Proxy

Configuration Files and Variables

You can configure Nextcloud using environment variables, which is a convenient way to set up your installation. This allows you to preconfigure everything that would otherwise be prompted for by the Nextcloud Installation Wizard.

Credit: youtube.com, Docker Compose will BLOW your MIND!! (a tutorial)

To enable auto configuration, you can set the NEXTCLOUD_INIT_HTACCESS environment variable to true. This will run the occ maintenance:update:htaccess command after container initialization.

The image also supports setting environment variables from files using the FILE__ prepend. For example, you can set the MYVAR environment variable based on the contents of the /run/secrets/mysecretvariable file.

Here are some key environment variables to keep in mind:

  • NEXTCLOUD_INIT_HTACCESS (not set by default) Set it to true to enable run occ maintenance:update:htaccess after container initialization.
  • NEXTCLOUD_UPDATE (default: 0)
  • MariaDB 10.5 is the latest supported version

Viewing config.php

Viewing config.php can be a bit misleading, as it only shows you the image's specific config values, not the actual running config. This is because Nextcloud supports multiple config.php files.

You should use Nextcloud's occ config:list system command to get a complete view of your merged configuration. This is especially useful for troubleshooting or reporting a bug.

The occ config:list command automatically omits sensitive values like passwords and secrets from the output by default. This is a great feature for sharing your config with others without exposing sensitive information.

You can use the --private flag to output all configuration values, including passwords and secrets. This is useful if you need to troubleshoot a sensitive issue.

Here are some key config values you might need to know about:

  • NEXTCLOUD_UPDATE (default: 0)

Custom App Directories

Credit: youtube.com, 4. Folder Structure and Configuration File

Custom App Directories can be made available to the web server by adding a volume, just like in the example: After adding a volume, you can set the path in your config.php file to point to your custom apps folder.

The recommended way to do this is to use a volume, which allows your custom folder to be accessible by the web server. This is a crucial step if you're using custom app directories.

You can set the path in your config.php file to point to your custom apps folder, using the syntax "path" => OC::$SERVERROOT . "/your_custom_apps_folder". Make sure to replace "/your_custom_apps_folder" with the actual path to your custom apps folder.

By following these steps, you'll be able to make your custom app directories accessible to the web server, and you'll be one step closer to getting your custom apps up and running.

Configuring Upload Size

To configure the upload size in NGINX, you need to set the max body size in the config file. This can be done by writing a specific line in the NGINX config file that your Dockerfile will copy.

A fresh viewpoint: Nextcloud Nginx

Credit: youtube.com, How to Increase the Maximum File Upload Size in WordPress | 9TO5.Host

Setting the max body size to 10 gigabytes allows for large uploads, making it suitable for applications that require high storage capacity. The max body size can be adjusted according to your specific needs.

Disabling proxy buffering is also a crucial step in configuring upload size. This ensures that the request is immediately passed on to your Nextcloud Docker container, allowing for efficient data transfer.

User Management and Access

With Nextcloud Docker Compose, you can easily manage user access to your files and folders.

You can create new users and set their permissions using the `nextcloud:admin` user.

To add a new user, run the `oc adduser` command, which allows you to specify the username, password, and email address for the new user.

Initial Admin Account

To set up your initial admin account, you can specify the admin user and password in your Nextcloud configuration. This can be done by setting the NEXTCLOUD_ADMIN_USER and NEXTCLOUD_ADMIN_PASSWORD variables.

Credit: youtube.com, Change a user to an Administrator Account | Short Tips

If you provide both variables, you can auto-configure your initial admin user and password, which will result in a fully automated installation of Nextcloud. This means you'll bypass the web-based installation wizard.

To auto-configure your admin user and password, you need to set both NEXTCLOUD_ADMIN_USER and NEXTCLOUD_ADMIN_PASSWORD variables. This will allow you to create a fully automated installation process.

Here are the variables you need to set:

  • NEXTCLOUD_ADMIN_USER: Name of the Nextcloud admin user.
  • NEXTCLOUD_ADMIN_PASSWORD: Password for the Nextcloud admin user.

Trusted Domains

Trusted domains are an essential aspect of user management and access, allowing you to specify which domains are trusted by your system.

You can set one or more trusted domains through an environment variable, which will be added to the configuration after installation.

The environment variable NEXTCLOUD_TRUSTED_DOMAINS can be used to specify a list of trusted domains. This list is optional and can be space-separated.

Collaborative Editing

Collaborative editing can be a bit tricky to set up, but don't worry, I've got the lowdown.

Collabora/CODE and OnlyOffice, Nextcloud's built-in collaborative editing packages, only work on x86_64 systems with glibc. This means they're not compatible with our images.

Credit: youtube.com, Understanding Editing & Collaboration 🖥️💡

To get them working, you'll need to create separate containers for each and set them up in Nextcloud with their respective connector addons. This will allow you to take advantage of their collaborative editing features.

If they're auto-installed, those built-in packages may cause instability and should be removed to prevent any issues.

Networking and Access

To make your Nextcloud accessible from the internet, you'll need to add SSL encryption. This is mandatory for internet access.

You can use the TRUSTED_PROXIES approach to specify trusted proxies and disable rewrite IP. This involves setting APACHE_DISABLE_REWRITE_IP to 1 and adding the reverse proxy's IP address to TRUSTED_PROXIES in CIDR notation.

If the TRUSTED_PROXIES approach doesn't work, you can try using fixed values for overwrite parameters. These include OVERWRITEHOST, OVERWRITEPROTOCOL, OVERWRITECLIURL, OVERWRITEWEBROOT, and OVERWRITECONDADDR. You can also specify HTTP headers with the original client IP address using FORWARDED_FOR_HEADERS.

Here are the environment variables you can use to configure your Nextcloud:

  • APACHE_DISABLE_REWRITE_IP (not set by default): Set to 1 to disable rewrite IP.
  • TRUSTED_PROXIES (empty by default): A space-separated list of trusted proxies. CIDR notation is supported for IPv4.
  • OVERWRITEHOST (empty by default): Set the hostname of the proxy. Can also specify a port.
  • OVERWRITEPROTOCOL (empty by default): Set the protocol of the proxy, http or https.
  • OVERWRITECLIURL (empty by default): Set the cli url of the proxy (e.g. https://mydnsname.example.com)
  • OVERWRITEWEBROOT (empty by default): Set the absolute path of the proxy.
  • OVERWRITECONDADDR (empty by default): Regex to overwrite the values dependent on the remote address.
  • FORWARDED_FOR_HEADERS (empty by default): HTTP headers with the original client IP address

Proxy Setup

Credit: youtube.com, How to Setup Proxy on Windows | Proxy Integration Tutorial

To set up a proxy for your Nextcloud installation, you'll want to use a reverse proxy like NGINX. This will allow you to encrypt all traffic to your clients and make your Nextcloud installation accessible from the internet.

You can use a Dockerfile to create a custom NGINX configuration for your proxy. Create a directory to store this Dockerfile and start building your custom configuration.

For a fully automated setup, you can use containers like nginx-proxy and acme-companion, which handle SSL encryption and certificate renewal for you. Check the documentation for these containers before using them.

To enable SSL encryption, you'll need to set up a reverse proxy in front of your Nextcloud installation. You can use a signed certificate from Lets Encrypt by setting up your Docker Compose file to request a certificate using Lets Encrypt.

Here's a list of environment variables you can use to configure your proxy:

  • APACHE_DISABLE_REWRITE_IP (not set by default): Set to 1 to disable rewrite IP.
  • TRUSTED_PROXIES (empty by default): A space-separated list of trusted proxies. CIDR notation is supported for IPv4.
  • OVERWRITEHOST (empty by default): Set the hostname of the proxy. Can also specify a port.
  • OVERWRITEPROTOCOL (empty by default): Set the protocol of the proxy, http or https.
  • OVERWRITECLIURL (empty by default): Set the cli url of the proxy (e.g. https://mydnsname.example.com)
  • OVERWRITEWEBROOT (empty by default): Set the absolute path of the proxy.
  • OVERWRITECONDADDR (empty by default): Regex to overwrite the values dependent on the remote address.
  • FORWARDED_FOR_HEADERS (empty by default): HTTP headers with the original client IP address

Remember to check the documentation for your specific setup and make sure you're using the latest version of the image-specific configuration files. You can copy the latest config files from /usr/src/nextcloud/config to /var/www/html/config to ensure they're up-to-date.

Accessing the CLI

Credit: youtube.com, Part 1 Establish Basic Connections, Access the CLI, and Explore Help

Accessing the CLI is a straightforward process. You can use the Nextcloud command-line interface, also known as the occ command, to interact with your Nextcloud server.

To access the occ command, you can use the following command: docker exec -it nextcloud_app_1 occ. Alternatively, if you're using Docker Compose, you can use a compose.yaml file to set up your system.

Using a compose.yaml file is a great way to get a fully featured and functional Nextcloud setup. With Docker Compose, you can easily create a database container and add persistent data volumes.

To run Docker Compose, simply execute the command docker compose up -d, and you'll be able to access your Nextcloud server at http://localhost:8080/ from your host system.

Here's an interesting read: Nextcloud Occ Commands

Patricia Dach

Junior Copy Editor

Patricia Dach is a meticulous and detail-oriented Copy Editor with a passion for refining written content. With a keen eye for grammar and syntax, she ensures that articles are polished and error-free. Her expertise spans a range of topics, from technology to lifestyle, and she is well-versed in various style guides.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.