Install Latest Nextclod + Mariadb/Postgres/Sqlite + A+ Certificate or Selfsigned - 100% Handsfree on Docker -> Ready to login

This is a small howto install a (nearly) complete Nextcloud on Docker and configure it to use it out of the box.

First clone my github repo and change into the directory nextcloud_on_docker.

git clone

cd nextcloud_on_docker

Install ansible and some needed tools by running the following command with a user that can sudo or is root.


Right now this will run on Ubuntu 16/18, Debian 9, CentOS 7. Maybe on Redhat 7.
The script is prepared for Raspbian and CoreOS. But this is still under development. Pre-Alpha.

Now you can configure the whole thing by editing the file inventory and some other files.

First of all you must define the server fqdn. If you want to get a Letsencrypt certificate this must be a valid DNS record pointing to your server and port 80+443 must be open to the internet.
If you have a private server or you use for example an AWS domain name like you’ll end up with a selfsigned certificate.Which is fine but annoying because you have to accept this certificate manually in your browser.
If you don’t have a fqdn use the server IP address.

# Your domain name to get a letsencrypt certificate
nextcloud_server_fqdn       =

Letsencrypt wants your email address. Enter it here:

# Your email address for letsencrypt
ssl_cert_email =

Where to you want to find your nextcloud program, config, database and data files in the hosts filesystem.

# data dir
nextcloud_base_dir          = /opt/nextcloud

Define your admin user. Leave the password empty and a random one will be generated and displayed at the end of the playbook run.

# admin user
nextcloud_admin             = 'admin'
nextcloud_passwd            = ''

Your favorite database, name, user and password.
The db password will be generated and stored in {{ nextcloud_base_dir }}/secrets. In case you need it

# database settings (choose one)
# nextcloud_db_type           = 'mysql'        # (MariaDB)
# nextcloud_db_type           = 'pgsql'        # (PostgreSQL)

nextcloud_db_type           = 'sqlite'        # (SQLite)

# options for mariadb or postgres
nextcloud_db_host           = 'localhost'
nextcloud_db_name           = 'nextcloud'
nextcloud_db_user           = 'nextcloud'
nextcloud_db_prefix         = 'oc_'

If you want to setup the nextcloud mail system put your mail server config here.

# Nextcloud mail setup
nextcloud_configure_mail    = false
nextcloud_mail_from         =
nextcloud_mail_smtpmode     = smtp
nextcloud_mail_smtpauthtype = LOGIN
nextcloud_mail_domain       =
nextcloud_mail_smtpname     =
nextcloud_mail_smtpsecure   = tls
nextcloud_mail_smtpauth     = 1
nextcloud_mail_smtphost     =
nextcloud_mail_smtpport     = 587
nextcloud_mail_smtpname     =
nextcloud_mail_smtppwd      =

Backup will come soon.

# Install restic backup tool if backup_folder is not empty
# more info about restic:
backup_folder        = '' # e.g. /var/nc-backup
# crontab settings restic for restic
backup_day           = *
backup_hour          = 4
backup_minute        = 0

Online office and Talk support as well.

# Enable an Online Office Suite [collabora|onlyoffice|none]
# more info about collabora office:
# more info about onlyoffice office:

online_office     = none
# online_office     = collabora
# online_office     = onlyoffice

# Install turn server for Nextcloud Talk
# talk_install         = true

If you want to access your database through an admin web page set this value to true

# adminer is a webfront end for your database at https://nextcloud_server_fqdn/adminer
adminer_enabled      = false

If you want to access your traefik dashboard uncomment the traefik_api_user

# user for traefik dashboard at https://nextcloud_server_fqdn/traefik
# traefik_api_user      = traefik

Run the ansible playbook book.

ansible-playbook nextdocker.yml

Your nextcloud access credentials will be displayed at the end of the run.

ok: [localhost] => {
    "msg": [
        "Your Nextcloud at is ready.",
        "Login with user: admin and password: fTkLgvPYdmjfalP8XgMsEg7plnoPsTvp ",
        "Other secrets you'll find in the directory /opt/nextcloud/secrets "

If you want to get rid of the container run

ansible-playbook nextdocker.yml -e state=absent

Your data won’t be deleted. You have to do this manually by rm -rf …

1 Like

I just pushed a new version of the nextcloud_on_docker to github into a testing branch.

What’s new?

  • Talk
  • Collabora

If you want to test it just do a git checkout testing before edit the inventory and run the playbook.

Feedback and merge request welcome.

git clone
cd nextcloud_on_docker
git checkout testing
vim inventory 
ansible-playbook nextdocker

There is a new version of this playbook:

Traefik v2.2 config and Elasticsearch (still work in progress):

Don’t use them to update an existing installation. I’m pretty sure that would break things.

Feedback and PRs welcome.

thank you for this script Reiner_Nippes. I am new to docker and this is great way for me to experiment and learn.
For a long time I was using nextcloud under FreenNAS jail.
Just a quick question. Does docker installation consumes significanly more resources than the traditional install? On my new install , I moved 850GB of data and running it for 4 days, the load is higher than 1, although 1 client is connected. And it is only using 4 GB of ram out of 32. May be it is searching and doing initial data mining.
Any advice on fine tuning?

Linux 5.4.0-42-generic x86_64
Intel® Xeon® CPU E5-1650 v3 @ 3.50GHz (12 cores)
Virtual Machine XCP-ng Server

you won’t see this on that maschine. I’m running a nextcloud instance on a 2gb vserver. just file serving, noo apps, handful of user. but it works.

did you install elastic search? that could take a while.

if you want to tune your database: you have to check the docs on from mariadb and or postgres and follow their steps to use your own database config files.

e.g. you want to change some of the default settings of the postgres db.

read the wiki:

then find out how to get your changes into the postgres container:

if you want to change the start behaviour of the postgres container this would be the place:

1 Like