Nextcloud is a robust client-server software suite that lets you build your own file hosting service. It offers a safe and private substitute for well-known services like Dropbox, Office 365, and Google Drive. Nextcloud supports smooth document collaboration with integrated office suites like Collabora Online and OnlyOffice, making it a flexible option for individuals or organizations. With Nextcloud, your files, calendars, contacts, and other data are hosted on servers you trust, offering uncompromised privacy and security.
This tutorial will demonstrate how to install Nextcloud on Docker. Whether you’re setting up a small private cloud or a solution for thousands of users, Docker makes deployment quick and efficient. Let’s dive into this guide to create a fully-fledged Nextcloud environment.
Prerequisites
- A Virtual Machine (such as the ones provided by NodeShift) with:
- 2 vCPUs
- 2 GB RAM
- 10 GB SSD
- Ubuntu 22.04 VM
Note: The prerequisites for this are highly variable across use cases. One could use a high-end configuration for a large-scale deployment.
Step-by-step process to install Nextcloud on Docker
For this tutorial, we’ll use a CPU-powered Virtual Machine by NodeShift, which provides high-compute Virtual Machines at a very affordable cost on a scale that meets GDPR, SOC2, and ISO27001 requirements. It also offers an intuitive and user-friendly interface, making it easier for beginners to get started with Cloud deployments. However, feel free to use any cloud provider you choose and follow the same steps for the rest of the tutorial.
Step 1: Setting up a NodeShift Account
Visit app.nodeshift.com and create an account by filling in basic details, or continue signing up with your Google/GitHub account.
If you already have an account, login straight to your dashboard.
Step 2: Create a Compute Node (CPU Virtual Machine)
After accessing your account, you should see a dashboard (see image), now:
1) Navigate to the menu on the left side.
2) Click on the Compute Nodes option.
3) Click on Start to start creating your very first compute node.
These Compute nodes are CPU-powered virtual machines by NodeShift. These nodes are highly customizable and let you control different environmental configurations, such as vCPUs, RAM, and storage, according to your needs.
Step 3: Select configuration for VM
1) The first option you see is the Reliability dropdown. This lets you choose the uptime guarantee level you seek for your VM (e.g., 99.9%).
2) Next, select a geographical region from the Region dropdown where you want to launch your VM (e.g., United States).
3) Most importantly, select the correct specifications for your VM according to your workload requirements by sliding the bars for each option.
Step 4: Choose VM Configuration and Image
1) After selecting your required configuration options, you’ll see the available VMs in your region and as per (or very close to) your configuration. In our case, we’ll choose a ‘4 vCPUs/4GB/80GB SSD’ Compute node.
2) Next, you’ll need to choose an image for your Virtual Machine. For the scope of this tutorial, we’ll select Ubuntu, as we will deploy Nextcloud on Docker, which will be deployed on Ubuntu.
Step 5: Choose the Billing cycle and Authentication Method
1) Two billing cycle options are available: Hourly, ideal for short-term usage, offering pay-as-you-go flexibility, and Monthly for long-term projects with a consistent usage rate and potentially lower cost.
2) Next, you’ll need to select an authentication method. Two methods are available: Password and SSH Key. We recommend using SSH keys, as they are a more secure option. To create one, head over to our official documentation.
Step 6: Finalize Details and Create Deployment
Finally, you can also add a VPC (Virtual Private Cloud), which provides an isolated section for you to launch your cloud resources (Virtual machine, storage, etc.) in a secure, private environment. We’re keeping this option as the default for now, but feel free to create a VPC according to your needs.
Also, you can deploy multiple nodes at once by clicking + in the Quantity option.
That’s it! You are now ready to deploy the node. Finalize the configuration summary; if it looks good, go ahead and click Create to deploy the node.
Step 7: Connect to active Compute Node using SSH
As soon as you create the node, it will be deployed in a few seconds or a minute. Once deployed, you will see a status Running in green, meaning that our Compute node is ready to use!
Once your node shows this status, follow the below steps to connect to the running VM via SSH:
- Open your terminal and run the below SSH command: (replace root with your username and paste the IP of your VM in place of ip after copying it from the dashboard)
ssh root@ip
2) If SSH keys are set up, the terminal will authenticate automatically.
3) In some cases, your terminal may take your consent before connecting. Enter ‘yes’, and you should be connected.
Output:
Step 8: Install Docker
We’ll quickly cover the installation of Docker on our Ubuntu VM. However, we also have a detailed guide on installing Docker and its usage instructions.
1) Delete any unnecessary Docker installations
sudo apt-get remove docker docker-engine docker.io containerd runc
Output:
2) Update the package source-list
sudo apt-get update
Output:
3) Install dependencies
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
Output:
4) Use curl to 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
5) Add Docker’s stable repository to the source-list
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 package source-list again
sudo apt-get update
Output:
6) Install Docker with other dependencies
sudo apt-get install docker-ce docker-ce-cli containerd.io
Output:
7) Check the installation with test container hello-world
sudo docker run hello-world
Output:
If you also got the “Hello from Docker!” in the output, it confirms that the installation was successful.
Step 9: Install Docker Compose
Docker Compose is a tool that simplifies the management of multi-container Docker applications. Instead of running each container individually and managing their configurations manually, Docker Compose lets you define and orchestrate your entire application stack using a single YAML configuration file (docker-compose.yml).
Let’s move ahead and set up Docker Compose.
1) Enable universe repository
sudo add-apt-repository universe
Output:
3) Update the package source-list
sudo apt update
Output:
3) Install Docker Compose
sudo apt install docker-compose
Output:
4) Verify the installation
docker-compose --version
Output:
Step 10: Set up the Nextcloud Project Environment
Before we move on to the actual installation of Nextcloud, we first need to perform some preparatory steps to create a suitable project environment where we’ll launch our Nextcloud server. Follow the steps below to do the same:
1) Create a project directory
(replace nextcloud
with the name you want to give to your project directory)
mkdir nextcloud
2) Create configuration files
For this step, we’ll create two configuration files, docker-compose.yaml
and .env
, which will be used to configure the Docker container and Docker networks.
docker-compose.yaml
– container instructions to set up multi-container Docker applications in YAML (“Yet Another Markup Language”) format..env
– will be used to store the environment variables that are used inside the docker-compose.yaml configuration.
Use the following command one by one to create the above two files inside the nextcloud
project directory:
touch nextcloud/docker-compose.yaml
touch nextcloud/.env
3) Create a Docker network
We’ll set up a Docker network. All the containers that will be used for hosting Nextcloud, will communicate inside this network.
(replace nodeshift_network
with your preferred name)
docker network create nodeshift_network
Output:
Once we are done with the above steps, we can continue with the installation of Nextcloud.
Step 11: Complete Nextcloud Configuration
The next few steps will help you to configure your Nextcloud server settings, mainly the docker-compose.yaml file and later the .env file we created in the last step.
1) Configure reverse-proxy
A reverse proxy is used in a Nextcloud configuration to improve security, performance, and scalability. It can handle SSL encryptions for your server and enables you to use your own domain name instead of an IP address by routing the traffic. We’ll use Ngnix for this.
a) Use the following command to open the docker-compose.yaml file in Nano editor:
sudo nano nextcloud/docker-compose.yaml
b) Insert the following configuration details to the file, with the block proxy as our first service block.
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:
- nodeshift_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
After adding the above content, the file should look like this:
2) Configure MariaDB service
We’ll use MariaDB as our SQL-based database service to manage our data on Nextcloud. Add the db service block the file with the same indent as the proxy.
db:
image: mariadb
container_name: nextcloud-mariadb
networks:
- nodeshift_network
volumes:
- db:/var/lib/mysql
- /etc/localtime:/etc/localtime:ro
environment:
- MYSQL_ROOT_PASSWORD
- MYSQL_PASSWORD
- MYSQL_DATABASE
- MYSQL_USER
restart: unless-stopped
Notice the indentation. YAML is very strict about indentation. Hence, make sure all the service blocks (in the next steps as well) are in the same and equal indent; otherwise, the Nextcloud installation can fail and throw errors.
3. Configure the Nextcloud server
Finally, we will add the app service block defining the configuration for the Nextcloud server. We’ll add the other two containers as dependencies to ensure this container is the last one to start.
Add the following app configuration details in the same indent as proxy and db blocks
(replace <YOUR_SERVER_IP>
with your VM/machine’s IP address)
app:
image: nextcloud:latest
container_name: nextcloud-app
networks:
- nodeshift_network
depends_on:
- 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=<YOUR_SERVER_IP>
restart: unless-stopped
The file after editing looks like this:
4) Finalize the configuration
a) Finally, add the one final block in the same indent as services, as this one is not a service block.
volumes:
nextcloud:
db:
networks:
nodeshift_network:
The added block should look like this:
b) Finalize the content of docker-compose.yaml
Make sure that your whole file looks similar to this
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:
- nodeshift_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
db:
image: mariadb
container_name: nextcloud-mariadb
networks:
- nodeshift_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:
- nodeshift_network
depends_on:
- 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=<YOUR_SERVER_IP>
restart: unless-stopped
volumes:
nextcloud:
db:
networks:
nodeshift_network:
If the file content looks correct according to the above example, go ahead, save the file (Ctrl + O > ENTER), and exit the editor (Ctrl + X).
5) Edit environment variables
To secure the server, let’s add our MariaDB passwords to the .env file.
Open the .env file in the Nano editor:
sudo nano nextcloud/.env
Add the environment variables that are used in docker-compose.yaml
Please make sure to replace the values in the below file content and use strong passwords for your server.
MYSQL_ROOT_PASSWORD=mysqlroot
MYSQL_PASSWORD=mysql
MYSQL_DATABASE=nextcloud
MYSQL_USER=nextcloud
How it looks in the file:
Once done, save the file and exit the editor. Now, we are ready to move to the next step and initialize the installation of Nextcloud.
Step 12: Install Nextcloud
1) Move inside the Nextcloud project directory
(replace nextcloud
with the name of your project directory)
cd nextcloud
2) Initialize the Docker containers for installation
docker-compose up -d
the above command will create our Nextcloud multi-container app.
Output:
- Check if all containers are up and running
docker ps
Output:
You can also check the volumes:
docker volume ls
Output:
Step 13: Access Nextcloud Web-Interface
If all the above steps went correctly, you’ll be able to access your own Nextcloud server by using the below URL on your browser
(replace <YOUR_SERVER_IP>
with your VM’s IP address, the one used in docker-compose.yaml configuration)
http://<YOUR_SERVER_IP>
you should see an interface like this
Fill in the details as per the following information:
- Login – your preferred account name (e.g., admin)
- Password – a strong password for your Nextcloud account
- Database account – the
MYSQL_USER
in your .env - Database password – the
MYSQL_PASSWORD
in your .env - Database name – the
MYSQL_DATABASE
in your .env - Database host – the name of our database service block in the docker-compose.yaml file, which in our case is “
db
".
After this, click on “Install” to install and connect the app to your account, and you can start using the Nextcloud service.
Feel free to play around within the dashboard and customize it according to your or your team’s needs.
With this, we successfully installed and set up Nextcloud in our Ubuntu VM!
Conclusion
This guide walked you through the step-by-step process of installing Nextcloud on Docker. We covered the essential steps for setting up your Nextcloud client-server suite to host your files, ensuring a smooth and scalable deployment. With Docker, your app becomes smoother and more manageable to operate with. Additionally, by deploying on NodeShift Cloud, we simplified the entire process, by using a developer-friendly environment to streamline our Virtual Machine setup. Whether you’re managing personal data or deploying for a team, NodeShift Cloud provides affordable, customized solutions that enhance efficiency and scalability, helping you focus on your mainstream tasks.
For more information about NodeShift:
Top comments (0)