Nextcloud - One stop for all your data

nextcloud Apr 17, 2022

Do you use Google/Microsoft for Calendar, Contact, Drive space to store all your data? Want to migrate to a self-hosted solution? Nextcloud is the way for you.

Nextcloud is a self-hosted service which can handle all your storage, Calendar, Contacts with multiple integrations/plugins to choose from. Most importantly, your data stays with you. Privately. Securely.

I will guide here the installation of Nextcloud using docker. I would be using Redis container for caching purposes, MariaDB as Database. You can always add Traefik labels to your compose file to secure your ports and expose using a reverse-proxy. Checkout my Traefik tutorial here


Nextcloud would use a database container to store all the credentials, etc. You can create a new database container or use an existing one by creating a new database for nextcloud and providing Nextcloud the access to that database. You can even use any managed/unmanaged database from any cloud provider which has less latency from your infrastructure.

version: "3"
    container_name: nextcloud
      - PUID=1000
      - PGID=1000
      - TZ=Asia/Kolkata
      - REDIS_HOST=redis
      - REDIS_HOST_PORT=6379
      - /path/to/nextcloud/config:/config
      - /path/to/nextcloud/data:/data
    restart: always
      - 443:443
      ## Change proxy to the name of your docker network or you can remove this option to use the default bridge docker network
       - proxy

    container_name: mariadb
      - PUID=1000
      - PGID=1000
      - TZ=Asia/Kolkata
      - MYSQL_DATABASE=nextcloud
      - /path/to/mariadb/config:/config
      - /path/to/custom.cnf:/etc/my.cnf.d/custom.cnf
    restart: always
    ## Change proxy to the name of your docker network or you can remove this option to use the default bridge docker network
       - proxy

    image: redis:latest
    restart: always
    container_name: redis
    hostname: redis
      - /path/to/redis/data:/data
    ## Change proxy to the name of your docker network or you can remove this option to use the default bridge docker network
      - proxy

## Skip the below lines if you are using bridge network or replace with your network name 
    external: true

You need to change with your credentials and path in above compose file. Below is the content of custom.cnf which I personally use to optimize MariaDB

## custom configuration file, please be aware that changing options here may break things

nice		= 0

character-set-server	= utf8
max_connections		= 100
connect_timeout		= 5
wait_timeout		= 600
max_allowed_packet	= 16M
thread_cache_size       = 128
sort_buffer_size	= 4M
bulk_insert_buffer_size	= 16M
tmp_table_size		= 32M
max_heap_table_size	= 32M
# * MyISAM
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched. On error, make copy and try a repair.
myisam_recover_options = BACKUP
key_buffer_size		= 128M
#open-files-limit	= 2000
table_open_cache	= 400
myisam_sort_buffer_size	= 512M
concurrent_insert	= 2
read_buffer_size	= 2M
read_rnd_buffer_size	= 4M
# * Query Cache Configuration
# Cache only tiny result sets, so we can fit more in the query cache.
query_cache_limit		= 128K
query_cache_size		= 64M
# for more write intensive setups, set to DEMAND or OFF
#query_cache_type		= DEMAND
# * Logging and Replication
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /config/log/mysql/mysql.log
#general_log             = 1
# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf.
# we do want to know about network errors and such
log_warnings		= 2
# Enable the slow query log to see queries with especially long duration
slow_query_log_file	= /config/log/mysql/mariadb-slow.log
long_query_time = 10
#log_slow_rate_limit	= 1000
log_slow_verbosity	= query_plan

# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id		= 1
#report_host		= master1
#auto_increment_increment = 2
#auto_increment_offset	= 1
log_bin			= /config/log/mysql/mariadb-bin
log_bin_index		= /config/log/mysql/mariadb-bin.index
# not fab for performance, but safer
#sync_binlog		= 1
expire_logs_days	= 10
max_binlog_size         = 100M
# slaves
#relay_log		= /config/log/mysql/relay-bin
#relay_log_index	= /config/log/mysql/relay-bin.index
#relay_log_info_file	= /config/log/mysql/
# If applications support it, this stricter sql_mode prevents some
# mistakes like inserting invalid dates etc.
# * InnoDB
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
default_storage_engine	= InnoDB
# you can't just change log file size, requires special procedure
#innodb_log_file_size	= 256M
innodb_buffer_pool_size	= 1024M
innodb_log_buffer_size	= 8M
innodb_file_per_table	= 1
innodb_open_files	= 400
innodb_io_capacity	= 400
innodb_flush_method	= O_DIRECT
# * Security Features
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem

# * Galera-related settings
# Mandatory settings
# Allow server to accept connections on all interfaces.
# Optional setting

max_allowed_packet	= 16M

#no-auto-rehash	# faster start of mysql but no tab completion

key_buffer_size		= 16M

Don't be alarmed by the config file, this is the default file created by MariaDB and I have added only 3/4 lines which can optimize the DB performance. Rest all the configs are kept default. You can proceed to change the config if you have knowledge on MariaDB/Mysql else can just copy paste this and you are good to go.

Here I am using port 443 to expose Nextcloud. Database and Redis are not exposed to host for security reasons. Feel free to do it if you know what you are doing.

Use docker-compose up -d to pull and run the containers. Access the Nextcloud using your https://HOST:IP Nextcloud uses a self-signed SSL Certificate and you need to proceed with SSL Prompt. Initially you would be asked to provide Database credentials, host and port. Fill them and complete the installation.

Your Nextcloud docker is up and running now. Nextcloud is a highly customizable tool which can aggregate all your workflow like mails, tasks, calendar acting as a complete suite just like Google/Microsoft Workspace. Make sure to use the Apps sections to explore and add required Apps.