An Interest In:
Web News this Week
- March 21, 2024
- March 20, 2024
- March 19, 2024
- March 18, 2024
- March 17, 2024
- March 16, 2024
- March 15, 2024
How to deploy NextCloud in your Linux Server with docker and SSL
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 its not free. We pay for those free spaces with the personal data they collected. Its 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 clients 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 your choose Nextcloud Enterprise which comes with the support. For example, if you choose the Contabo provider, you can have your fully functional cloud solution with 200GB SSD, 8GO of RAM, and 4vCPU for only $6.99 a month.
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
Deployment of NextCloud
POSTGRES_PASSWORD=yourdbstrongpasswordPOSTGRES_DB=nextcloudPOSTGRES_USER=nextcloud
db.env file
version: "3.9"services: nextcloud_db: image: postgres:alpine restart: always volumes: - nextcloud_dbdata:/var/lib/postgresql/data env_file: - db.env redis: image: redis:alpine restart: always nextcloud_web: image: nextcloud:apache restart: always volumes: - nextcloud:/var/www/html environment: - VIRTUAL_HOST=cloud.yourdomain.com - LETSENCRYPT_HOST=cloud.yourdomain.com - LETSENCRYPT_EMAIL=yourmail # <===== For let's encrypt - POSTGRES_HOST=nextcloud_db - REDIS_HOST=redis env_file: - db.env depends_on: - nextcloud_db - redis cron: image: nextcloud:apache restart: always volumes: - nextcloud:/var/www/html entrypoint: /cron.sh depends_on: - nextcloud_db - redisvolumes: nextcloud_dbdata: nextcloud:#Use this configuration in production with nginx-proxy containernetworks: default: external: name: nginx-proxy
docker-compose.yml file
Login to your Linux server and type the following command:
mkdir nextcloud && cd nextcloudnano 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: Dont forget the change the environment variables VIRTUAL_HOST and LETSENCRYPT_HOST with your domain name and LETSENCRYPT_EMAIL with your email address.
Now, its 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 lets 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, its 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 doesnt 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. Dont 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. Its 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. Its 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
Its 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 Lets Encrypt. Another thing you can do now is to deploy a keycloak SSO solution next to this to centralize authentication among all your application. Its pretty easy at this step and doesnt 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.
Original Link: https://dev.to/tderick/how-to-deploy-nextcloud-in-your-linux-server-with-docker-and-ssl-198k
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To