When you create your account and store your documents, images, etc in Google drive or dropbox, you are not the master of your data. Generally, we say that we use Google or Microsoft one drive for free but it’s not free. We pay for those free spaces with the personal data they collected. It’s where NextCloud comes in. In simple words, Nextcloud is your cloud infrastructure under your control.
What is NextCloud ?
NextCloud is open-source software that allows you to run your personnel cloud service like dropbox. It gives you access to all your files wherever you are. It allows you to share and collaborate on documents, send and receive email, manage your calendar and have video chats. You can install the Nextcloud server software free on your Linux server and the client’s software on your Windows, OS X, or Linux machine, Android, and IOS mobile phone.
The main drawback here is you need to pay for your Linux server to your VPS provider and you will be responsible for your server maintenance unless you choose Nextcloud Enterprise which comes with the support.
Pre-requisite before the installation of Nextcloud
As we will deploy our NextCloud instance with docker, you need to have:
- A Linux Server with SSH and root access
- Docker and docker-compose installed on that server
- A domain name pointed to that server
To perform this tutorial, you can easily create a small droplet(Linux Server) for free on DigitalOcean. They offer DigitalOcean offers 200$ free credits for 60 days. Everything being said, let’s focus on the tutorial.
Deployment of NextCloud
Login to your Linux server and type the following command:
mkdir nextcloud && cd nextcloud
nano db.env
Copie the content of the db.env in the above GitHub gist and paste it into the newly created file. After this, create a docker-compose.yml file and copy the content of the docker-compose.yml in the above Github gist and paste it into.
Note: Don’t forget the change the environment variables VIRTUAL_HOST and LETSENCRYPT_HOST with your domain name and LETSENCRYPT_EMAIL with your email address.
Now, it’s time to create the docker network that would be used to drive secure traffic to our Nextcloud instance through our domain name.
docker network create nginx-proxy
Then let’s start our Nextcloud instance.
docker-compose up --build -d
Our Nextcloud instance is now running but is not accessible from the internet. We will now configure Nginx-proxy to drive traffic to our Nextcloud instance. We will explain our docker-compose file after making our instance fully functional.
Installation of Nginx-proxy and acme-compagnon
Nginx proxy is a container running Nginx and docker-gen which is a service that generates reverse proxy configs for Nginx and reloads Nginx when containers are started or stopped.
This container is mounted on a docker socket to capture all events created by docker to be able to proxied any container with an env variable VIRTUAL_HOST
define. All containers that want to be proxied by Nginx-proxy must be connected to the same network with it. To know more about Nginx-proxy, visit the GitHub of the project.
ACME-compagnon is a compagnon for Nginx-proxy responsible to automate the creation, renewal, and use of SSL certificates for proxied Docker containers through ACME protocol. For more information about acme-compagnon, visit the GitHub of the project.
I have a ready-to-use template for Nginx-proxy in my repository. You just need to clone and run it. I also use this template in all my projects. With this configuration, it’s easy to make things work in less than a minute. Just use the following command.
cd ~
git clone https://gitlab.com/tderick/nginx-proxy-conf.git
docker-compose up --build -d
Now, your Nextcloud instance is running, and you can access it via your domain name.
When you install Nextcloud, it doesn’t come with an admin account by default. You need to create it. Just fill in the form on the first page and hit the install button. Don’t put email as username. if you do, you have the following error:
After putting in a username and password, we will arrive at the following page listing the recommended apps to install in our instance.
We can see there are applications for:
- Calendar
- Contacts
- Online edition and collaboration
We will install other applications later. Just hit the install recommended apps button.
Our nextcloud instance is now installed and ready to use. Now, we can explain our docker-compose file to understand the magic behind this.
Docker-compose file explanation
In this docker-compose file, we use version 3.9 and we expose three services, two volumes, and one default external network.
nextcloud_db service
Nextcloud support multiple DBMS: MySQL, MariaDB, Oracle, PostgresSQL. It’s up to you to choose your favorite DBMS. We choose to use Postgres as it is a very powerful solution.
redis service
Redis is an excellent modern memory cache solution to use for distributed caching. It’s used by Nextcloud to significantly improve the Nextcloud server performance with memory caching where frequently-requested objects are stored for faster retrieval.
nextcloud_web service
It’s the official Nextcloud container with all the features offered.
cron service
Cron is a simple time-based job scheduler that runs small tasks on its own without the intervention of the user or the administrator. Cron is also an important part for Nextcloud to be running efficiently.
Wrap up
In this tutorial, we explain to you how to deploy your Nextcloud instance in your Linux server with docker-compose and secure it with a free SSL certificate issued by Let’s Encrypt. Another thing you can do now is to deploy a keycloak SSO solution next to this to centralize authentication among all your application. It’s pretty easy at this step and doesn’t affect the previous installation. If you have any questions, leave a comment.
If you like this tutorial, you can buy me coffee. In the upcoming tutorial, we will more explore Nextcloud.
I am a Master’s student in computer science passionate about DevOps, Cloud Computing, AI, and BI. I am also a web developer, especially with Django and Laravel Frameworks. I love to share things that work for me with others to save them time searching through the internet to solve the same problem.
One thought on “How to deploy NextCloud in your Linux Server with docker and SSL”