Nextcloud with Docker: How to install
Nextcloud has established itself as a popular open-source solution. In addition to its clients for desktop and mobile operating systems, the software also features a server component. We show you how to install a Nextcloud server in a Docker environment.
Thanks to free starting credit, you can test the IONOS cloud server for 1 month free of charge (or until the credit is used up) and experience the perfect combination of performance and security!
Installing Nextcloud with Docker
Nextcloud is an open-source cloud solution that came about as a fork from the ownCloud project. Its range of features is comparable with proprietary cloud solutions like Microsoft 365 and Google Workspace. Nextcloud synchronises data like calendars and contacts across users and devices. Aside from the customary file syncing, the software provides features for team collaboration and communication.
As is the case with other comparable cloud solutions, Nextcloud includes a server component as well as clients for desktop and mobile operating systems. The Nextcloud server manages data and communicates with the clients; you can access the server from a client-independent web interface.
We’ll show you how to install a Nextcloud server on Ubuntu using Docker Compose and cloud infrastructure. It’s also possible to install the software on your own hardware and set up Nextcloud on, for example, a Raspberry Pi.
Nextcloud and ownCloud have a lot in common. In our guide ‘ownCloud vs. Nextcloud’ we lay out the key differences for you.
Architecture of Nextcloud on Docker
Let’s take a look the components of Nextcloud servers with Docker. Aside from the Nextcloud software itself, there are three containerised services that come into play. To provision the container network, we’ll use the Docker tool Compose. The individual services are:
- Nginx Reverse Proxy: Used to realise encrypted HTTPS connections when accessing Nextcloud
- Let’s Encrypt: Used to set up SSL certificates automatically
- MariaDB: Used to store data created by the server during Nextcloud use
- Nextcloud server: Provides Nextcloud functionality; communicates with Nextcloud clients and hosts the web interface
Preparing for your Nextcloud server installation
The first step is installing Docker Engine and Docker Compose. Docker Engine will provide the core container functionality, while Docker Compose makes it possible to manage related container networks. If you already have Docker Engine and Docker Compose installed, you can skip this section.
Installing Docker Engine on Ubuntu
Now we’ll show you how to install Docker Engine on Ubuntu, based on the official installation manual. You can find instructions for installing the software on other Linux distributions on the Docker website.
- Delete any other Docker installations:
sudo apt-get remove docker docker-engine docker.io containerd runc
- Update the installer:
sudo apt-get update
- Prepare the repositories:
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
- Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
- Set up a stable Docker repository:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
- Update the repositories:
sudo apt-get update
- Install Docker Engine, along with dependencies:
sudo apt-get install docker-ce docker-ce-cli containerd.io
- Lastly, we’ll execute the test container ‘Hello World’. If Docker Engine was properly installed, the container will be executed and output the message.
sudo docker run hello-world
Install Docker Compose on Ubuntu
Let’s now turn to Docker Compose. Installing this software is easier than installing Docker Engine - there are just a few steps.
- Activate Ubuntu’s Universe repository:
sudo add-apt-repository universe
- Update the package manager:
sudo apt update
- Install Docker Compose:
sudo apt install docker-compose
- Check whether Docker Compose was successfully installed:
docker-compose --version
If the version number is shown, then Docker Compose was successfully installed.
Installing the Nextcloud server
As soon as you’ve installed Docker Engine and Docker Compose, you can get started with installing Nextcloud itself. We’ll configure individual Docker containers for the different services. Two configuration files will be of use in configuring the containers and the Docker volumes and Docker networks:
File | Explanation |
---|---|
docker-compose.yaml | Docker Compose instructions in YAML format for building multi-container applications |
.env | Text file with environment variables; one variable definition per line |
Docker Compose will be used to manage multi-container applications. That’s where the Docker Compose instructions come in — they define how the application should be structured and how the various components interact with each other. They describe the individual services, Docker elements, and settings and are written in YAML (‘Yet Another Markup Language’). We’ll build the file used for this (docker-compose.yaml) step by step.
Aside from docker-compose.yaml, we’ll need one more file, which contains the environment variables that will be integrated into the Docker Compose instructions. Standard practice is to place the environment variables in a .env file in the project folder, along with the values. The .env file isn’t included in the version control system, protecting sensitive data from accidental exposure.
The use of an .env file makes it unnecessary to define different settings for the different app environments. To use different settings for a live site and a staging site, for example, you need only change the .env file.
Creating the necessary structures for a Nextcloud server
To begin our Nextcloud server installation, we’ll need a handful of structures. We’ll create them in the following steps:
- Create a project folder. Set up the folder nextcloud-docker in your home directory:
mkdir ~/nextcloud-docker/
- Create the files. We’ll create the files docker-compose.yaml and .env in the project folder:
touch ~/nextcloud-docker/docker-compose.yaml
touch ~/nextcloud-docker/.env
- Create Docker network. We’ll use the docker command to set up a new network. The four containers will then communicate inside the network.
docker network create nextcloud_network
Once we’ve set up these structures, we can continue with the installation of our Nextcloud server.
Configuring a reverse proxy for the Nextcloud server
To start our installation of the Nextcloud server, we’ll configure the reverse proxy, for which we’ll use Nginx. Since we’re putting together our application from containers, most of the installation will take place in the file docker-compose.yaml. We’ll show you in detail how to edit this file. You’ll also follow the same patterns in subsequent installation steps:
- Open the file docker-compose.yaml for editing. The following command will open the empty file in the editor ‘Nano’.
nano ~/nextcloud-docker/docker-compose.yaml
- Insert the following code block into Nano and save the file. To close the file, use the shortcut [Ctrl] + [X]. You’ll be asked whether you want to save the file. Answer with ‘y’ for ‘yes’. Confirm the use of the existing file name with the [Enter] key. Alternatively, you can leave the editor open and use the shortcut [Ctrl] + [O] (‘Write out’) to write the editor text into the file.
version: '3'
services:
proxy:
image: jwilder/nginx-proxy:alpine
labels:
- "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true"
container_name: nextcloud-proxy
networks:
- nextcloud_network
ports:
- 80:80
- 443:443
volumes:
- ./proxy/conf.d:/etc/nginx/conf.d:rw
- ./proxy/vhost.d:/etc/nginx/vhost.d:rw
- ./proxy/html:/usr/share/nginx/html:rw
- ./proxy/certs:/etc/nginx/certs:ro
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/tmp/docker.sock:ro
restart: unless-stopped
What do the individual entries mean? First, we instruct Docker Compose to create a new service with the name proxy and use a Nginx image based on Alpine Linux. Then we specify that the reverse proxy should communicate with the other services using the Docker network nextcloud_network.
We map the standard HTTP and HTTPS ports 80 and 443 from the host system onto the container. This routes incoming connections through the proxy. In the last step of the configuration, we create various Docker volumes and specify that the reverse proxy should be automatically restarted unless it’s explicitly stopped.
Configuring the Let’s Encrypt service for the Nextcloud server
The next step is installing Let’s Encrypt. This enables encrypted communication with the Nextcloud server via HTTPS.
- Open the file docker-compose.yaml for editing:
nano ~/nextcloud-docker/docker-compose.yaml
- Add another service block. Proceed as in the previous section and pay special attention to the indentation. The beginning of the block that starts with letsencrypt: has to be at the same level as proxy:. This is also true of the service blocks that come later.
letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: nextcloud-letsencrypt
depends_on:
- proxy
networks:
- nextcloud_network
volumes:
- ./proxy/certs:/etc/nginx/certs:rw
- ./proxy/vhost.d:/etc/nginx/vhost.d:rw
- ./proxy/html:/usr/share/nginx/html:rw
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
restart: unless-stopped
Once again, we define a new service with the name letsencrypt, which is based on the container letsencrypt-nginx-proxy-companion. We specify that the service is dependent on the reverse proxy service and communicates in the same Docker network. We also define the Docker volumes required for data exchange. Just as above, we specify that the service should be automatically restarted unless it was explicitly stopped.
You’re looking for professional-level encryption for your website? Purchase your own affordable SSL certificate with IONOS!
Configuring the MariaDB service
We’ve now completed half of the installation! Let’s continue with the MariaDB database, which is required for managing the data created when using Nextcloud. The actual storage in Docker volumes will happen outside the container.
- Open the file docker-compose.yaml for editing:
nano ~/nextcloud-docker/docker-compose.yaml
- Add another service block:
db:
image: mariadb
container_name: nextcloud-mariadb
networks:
- nextcloud_network
volumes:
- db:/var/lib/mysql
- /etc/localtime:/etc/localtime:ro
environment:
- MYSQL_ROOT_PASSWORD
- MYSQL_PASSWORD
- MYSQL_DATABASE
- MYSQL_USER
restart: unless-stopped
Most of the settings should be familiar at this point. First, we define a service db, which is based on the Docker image mariadb. We then define the same network as before, nextcloud_network, and a Docker volume for storing data.
What’s new in this configuration block is the use of environment variables. In the environment section, we specify the names of the environment variables for MariaDB. The values will be read from the .env file when Docker Compose is executed later.
Configuring the Nextcloud server container
The time has come: Now we’ll install the Nextcloud server software.
- Open the file docker-compose.yaml for editing:
nano ~/nextcloud-docker/docker-compose.yaml
- Add another service block:
app:
image: nextcloud:latest
container_name: nextcloud-app
networks:
- nextcloud_network
depends_on:
- letsencrypt
- proxy
- db
volumes:
- nextcloud:/var/www/html
- ./app/config:/var/www/html/config
- ./app/custom_apps:/var/www/html/custom_apps
- ./app/data:/var/www/html/data
- ./app/themes:/var/www/html/themes
- /etc/localtime:/etc/localtime:ro
environment:
- VIRTUAL_HOST
- LETSENCRYPT_HOST
- LETSENCRYPT_EMAIL
restart: unless-stopped
Here we create a service with the name app, which is based on the Docker image nextcloud and communicates with the network nextcloud_network. To ensure that the Nextcloud container is started last, we specify the other services as dependencies. We also define the required Docker volumes and environment variables.
Finishing up the Nextcloud server configuration
To conclude our configuration of the Nextcloud server, we need to make a few more entries in the docker-compose.yaml file. We’ll also create the .env file and fill it with the corresponding values.
- Open the file docker-compose.yaml for editing:
nano ~/nextcloud-docker/docker-compose.yaml
- Insert the following blocks. Note that they aren’t services blocks; their indentation should be at the same level as services:.
volumes:
nextcloud:
db:
networks:
nextcloud_network:
- Open the empty .env file for editing:
nano ~/nextcloud-docker/.env
- Write the environment variables including their values into the .env file. We’ll copy the following code into the editor window and replace the with the desired values before saving.
# MariaDB
MYSQL_ROOT_PASSWORD=toor
MYSQL_PASSWORD=mysql
MYSQL_DATABASE=nextcloud
MYSQL_USER=nextcloud
# Nextcloud
VIRTUAL_HOST=<your.domain></your.domain>
LETSENCRYPT_HOST=<your.domain></your.domain>
LETSENCRYPT_EMAIL=<your@email></your@email>
- After saving, we’ll display the contents of the .env file to check whether the values were entered correctly.
cat ~/nextcloud-docker/.env
Complete Nextcloud server configuration
Before we hand over the configuration to Docker Compose and create and start the containers, we’ll make sure that everything that’s needed is in place.
- Output the existing configuration:
cat ~/nextcloud-docker/docker-compose.yaml
- Compare against our template. The output configuration should match up with the following code:
version: '3'
services:
proxy:
image: jwilder/nginx-proxy:alpine
labels:
- "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true"
container_name: nextcloud-proxy
networks:
- nextcloud_network
ports:
- 80:80
- 443:443
volumes:
- ./proxy/conf.d:/etc/nginx/conf.d:rw
- ./proxy/vhost.d:/etc/nginx/vhost.d:rw
- ./proxy/html:/usr/share/nginx/html:rw
- ./proxy/certs:/etc/nginx/certs:ro
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/tmp/docker.sock:ro
restart: unless-stopped
letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: nextcloud-letsencrypt
depends_on:
- proxy
networks:
- nextcloud_network
volumes:
- ./proxy/certs:/etc/nginx/certs:rw
- ./proxy/vhost.d:/etc/nginx/vhost.d:rw
- ./proxy/html:/usr/share/nginx/html:rw
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
restart: unless-stopped
db:
image: mariadb
container_name: nextcloud-mariadb
networks:
- nextcloud_network
volumes:
- db:/var/lib/mysql
- /etc/localtime:/etc/localtime:ro
environment:
- MYSQL_ROOT_PASSWORD
- MYSQL_PASSWORD
- MYSQL_DATABASE
- MYSQL_USER
restart: unless-stopped
app:
image: nextcloud:latest
container_name: nextcloud-app
networks:
- nextcloud_network
depends_on:
- letsencrypt
- proxy
- db
volumes:
- nextcloud:/var/www/html
- ./app/config:/var/www/html/config
- ./app/custom_apps:/var/www/html/custom_apps
- ./app/data:/var/www/html/data
- ./app/themes:/var/www/html/themes
- /etc/localtime:/etc/localtime:ro
environment:
- VIRTUAL_HOST
- LETSENCRYPT_HOST
- LETSENCRYPT_EMAIL
restart: unless-stopped
volumes:
nextcloud:
db:
networks:
nextcloud_network:
If your version of the YAML file matches ours, you can continue on to the next and final step.
Complete Nextcloud server installation
To create a Nextcloud server as a multi-container app from the Docker Compose instructions, we’ll execute the following command on the command line:
cd ~/nextcloud-docker/ && docker-compose up -d
Then we’ll check whether the container was started:
docker ps -a
The list of running containers should contain the four containers defined in the docker-compose.yaml file.