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 https://github.com/ReinerNippes/nextcloud_on_docker

cd nextcloud_on_docker

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

./prepare_system.sh

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 ec2-52-3-229-194.compute-1.amazonaws.com 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       = nextcloud.example.org

Letsencrypt wants your email address. Enter it here:

# Your email address for letsencrypt
ssl_cert_email = nextcloud@example.org

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: https://restic.readthedocs.io/en/latest/
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: https://www.collaboraoffice.com/
# more info about onlyoffice office: https://www.onlyoffice.com

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 https://nextcloud.example.org 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 https://github.com/ReinerNippes/nextcloud_on_docker
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 hub.docker.com 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: https://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server

then find out how to get your changes into the postgres container: https://stackoverflow.com/questions/30848670/how-to-customize-the-configuration-file-of-the-official-postgresql-docker-image

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

1 Like

suddenly I am getting
404 page not found
error. did not change any config. any idea?
portainer site works, but nextcloud gives this error.

no. sorry.
you checked the logs?

thank you for quick response. the container logs does not show any problem. is there any specific log/logs?
edit: under labels tab of nextcloud

|com.centurylinklabs.watchtower.enable |true|
|traefik.enable |false|

that’s correct. if you are using nginx/php-fpm. nginx is traefik.enable: true

do you know if the 404 error is caused by the traefik or nginx container?

not using nginx/php-fpm


when I enable adminer I can also access it. so the only problem is accessing nextcloud container. this error is from traefik I guess. even https works. here is the site: https://www.baser.online

grafik

yes. you do use the fpm image. if you killed the nginx container you’ll get the 404 error

ohh, still newbei to the dockers. no idea how it is removed/killed. (I never touch the containers)
how can I re-install it. thank you for your time.
I found the unused image nginx:alpine)

edit: I checked the watchtower logs (it is the updater/maintainer), I think someting happened there.
time=“2020-12-16T00:00:20Z” level=info msg=“Found new nginx:alpine image (sha256:…)”

time=“2020-12-16T00:00:27Z” level=info msg=“Stopping /nginx (…) with SIGTERM”

time=“2020-12-16T00:00:33Z” level=info msg=“Creating /nginx”

time=“2020-12-16T00:00:55Z” level=info msg=“Removing image sha256:…”

time=“2020-12-18T00:00:30Z” level=info msg=“Found new nginx:alpine image (sha256:…)”

well. watchtower shouldn’t kill the nginx container.

it should be possible to re-create the container by re-running the playbook. (better make a backup of your data. you never know.)

wow, Thank you so much Reiner.
just running the command from original nextcloud_on_docker folder did the job.
" ansible-playbook nextdocker.yml"
now it works.
now I wonder should I update your playbook (keeping inventory data) and re-run it to have the latest playbook?

no.

better not. sometimes i change thinks that would break your setup. and there is no need for an update. you won’t get a “better” setup.

1 Like

Thanks to Reiner_Nippes script, my nextcloud docker is automatically updates and be always the current version. As of today my nexcloud is version 21.0. I have a question about PHP 8.0. Now with PHP8 and even with PHP 8.0 preload JIT, nextcloud says it will be almost 1.6X faster. How will we update? The nextcloud fpm-alphine will update to PHP 8 or we should change the dockers ENV settings.
Thank you

i think nextcloud will do this. they will change the base image of the fpm-alpine image.

there is a 8.0.2-fpm-alpine image on docker hub. but you would have to build your own image. (which is not part of my playbook.)

we simply have to wait.

1 Like

we simply have to wait.

You’re right, it is better to have official integration.