NextCloud is a popular open source file sharing and collaboration platform that lets you store, share, and collaborate on documents, photos, videos, and more.
In this article, we will walk you through the process of installing NextCloud in Docker Compose.
Installing Docker and Docker Compose
Before you get started, you need to install Docker and Docker Compose. You can find installation instructions for your operating system on our blog for Centos 7 or Ubuntu 20.04.
Install Docker Compose
curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin /docker-compose
Set permissions to launch.
chmod +x /usr/local/bin/docker-compose
Check how Docker-Compose was installed:
docker-compose --version
Create a directory to store your Nextcloud data
This directory will store user data and files. For example, you can create the /opt/nextcloud-data directory and change to:
mkdir /opt/nextcloud-data && cd /opt/nextcloud-data
Create a Docker Compose File
Next, you need to create a Docker Compose file that defines the services for NextCloud. To create the file, open a text editor and create a new file called docker-compose.yml. Copy and paste the following code into a file:
version: '3'
services:
nextcloud_db:
image: mariadb:10.5
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
restart: always
volumes:
- ./nextcloud-db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=vAfrhiwaj7spoe1DBARv
- MYSQL_PASSWORD=22CifgJLFFdeKKuprzT6
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
nextcloud:
image: nextcloud
ports:
- 9090:80
links:
- nextcloud_db
volumes:
- ./nextcloud:/var/www/html
environment:
- NEXTCLOUD_DATA_DIR=/var/www/html/data
- MYSQL_PASSWORD=22CifgJLFFdeKKuprzT6
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_HOST=nextcloud_db
restart: always
After saving the file, run the following command in the folder where the yaml file is located:
docker-compose up -d
And we can observe the deployment of containers.
After successful deployment, the containers will be launched.
Let's consider the Docker Compose configuration file for running two containers: MariaDB database and Nextcloud web application.
In the first section, we define the nextcloud_db service, which will represent the MariaDB database. For this service, we use the official Docker image mariadb:10.5.
Then we set several parameters:
- command: This parameter sets the command that will be run inside the container. Here we set the parameters for MariaDB to use READ-COMMITTED as the transaction isolation level and ROW as the binary log format.
- restart: This parameter specifies that the container should be automatically restarted in case of a failure.
- volumes: This parameter mounts the local directory ./nextcloud-db inside the container at the path /var/lib/mysql. This allows for saving the database data on the local disk.
Then we set environment variables:
- MYSQL_ROOT_PASSWORD: This is the password for the MariaDB database superuser (root).
- MYSQL_PASSWORD: This is the password for the nextcloud database user.
- MYSQL_DATABASE: This is the name of the database that will be created for Nextcloud.
- MYSQL_USER: This is the name of the user that will be created for the Nextcloud database.
In the second section, we define the nextcloud service, which will represent the Nextcloud web application. For this service, we use the official Docker image nextcloud.
Then we set several parameters:
- ports: This parameter maps port 9090 on the local machine to port 80 inside the container. This allows for accessing Nextcloud from a web browser.
- links: This parameter links the container to the MariaDB database so that Nextcloud can use it to store data.
- volumes: This parameter mounts the local directory ./nextcloud inside the container at the path /var/www/html. This allows for saving the application data on the local disk.
Then we set environment variables:
- NEXTCLOUD_DATA_DIR: This is the path where Nextcloud will store data.
- MYSQL_PASSWORD: This is the password for the nextcloud database user.
- MYSQL_DATABASE: This is the name of the database created for Nextcloud.
- MYSQL_USER: This is the name of the user created for the Nextcloud database.
- MYSQL_HOST: This parameter specifies the database host name that the Nextcloud application should connect to.
Finally, we set the restart parameter to automatically restart the Nextcloud container in case of a failure.
Now in the browser line, write the IP of your server and the port that you set. In our case, this is 9090.
http://192.168.0.100:9090
Now we can log in. Enter your username and password in the field. They will be created when you enter the panel.
After authorization, we can observe the welcome window.
Overall, this Docker Compose configuration allows for easily running Nextcloud with a MariaDB database that stores data on the local disk. Thanks to this, you can easily deploy Nextcloud on your local machine or server to use it for storing files, calendars, and so on.
We also suggest you other useful articles: