Nextcloud in docker
guide by example
Purpose
File share & sync.
Files and directory structure
/home
└── ~
└── docker
└── nextcloud
├── 🗁 nextcloud-data
├── 🗁 nextcloud-data-db
├── 🗋 .env
├── 🗋 docker-compose.yml
└── 🗋 nextcloud-backup-script.sh
docker-compose
Official examples here
There are several options, default recomendation is apache. Alternative is php-fpm as a stand alone container with either apache or ngnix. Apache with php as a module is used in this setup.
Four containers are spin up
nextcloud-db- mariadb database where files and users meta data are storednextcloud- the nextcloudnextcloud-redis- in memory data store for faster and responsive interfacenextcloud-cron- for being able to run maintnance cronjobs
Two persinstent storages
nextcloud-databind mount - nextcloud app storage with web server and the worksnextcloud-data-dbbind mount - database storage
docker-compose.yml
version: '3'
services:
nextcloud-db:
image: mariadb
container_name: nextcloud-db
hostname: nextcloud-db
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
restart: unless-stopped
volumes:
- ./nextcloud-data-db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD
- MYSQL_PASSWORD
- MYSQL_DATABASE
- MYSQL_USER
nextcloud:
image: nextcloud:apache
container_name: nextcloud
hostname: nextcloud
restart: unless-stopped
depends_on:
- nextcloud-db
- nextcloud-redis
links:
- nextcloud-db
volumes:
- ./nextcloud-data/:/var/www/html
environment:
- MYSQL_HOST
- REDIS_HOST
- NEXTCLOUD_TRUSTED_DOMAINS
nextcloud-redis:
image: redis:alpine
container_name: nextcloud-redis
hostname: nextcloud-redis
restart: unless-stopped
nextcloud-cron:
image: nextcloud:apache
container_name: nextcloud-cron
hostname: nextcloud-cron
restart: unless-stopped
volumes:
- ./nextcloud-data/:/var/www/html
entrypoint: /cron.sh
depends_on:
- nextcloud-db
- nextcloud-redis
networks:
default:
external:
name: $DEFAULT_NETWORK
.env
# GENERAL
MY_DOMAIN=blabla.org
DEFAULT_NETWORK=caddy_net
TZ=Europe/Prague
# NEXTCLOUD-MARIADB
MYSQL_ROOT_PASSWORD=nextcloud
MYSQL_PASSWORD=nextcloud
MYSQL_DATABASE=nextcloud
MYSQL_USER=nextcloud
# NEXTCLOUD
MYSQL_HOST=nextcloud-db
REDIS_HOST=nextcloud-redis
NEXTCLOUD_TRUSTED_DOMAINS=
Reverse proxy
Caddy v2 is used, details here
Caddyfile
{
# acme_ca https://acme-staging-v02.api.letsencrypt.org/directory
}
nextcloud.{$MY_DOMAIN} {
reverse_proxy {
to nextcloud:80
}
}
First run
Extra info
-
check if redis container works
exec in to redis container:docker container exec -it nextcloud-redis /bin/sh
start monitoring:redis-cli MONITOR
in browse start browsing files on the nextcloud, there should be lot of activity in the monitoring -
check if cron container works
in settings > administration > basic settings
Background jobs should be set to Cron and the last job info should never be older than 10 minutes- in settings > administration > overview
nextcloud complains about missing indexes or big int
- in settings > administration > overview
-
in settings > administration > overview
nextcloud complains about missing indexes or big int- docker exec -it nextcloud /bin/sh
- chsh -s /bin/sh www-data
- su www-data
- cd /var/www/html
- php occ db:add-missing-indices
- php occ db:convert-filecache-bigint
-
in settings > administration > overview
not resolve "/.well-known/caldav" and "/.well-known/carddav"docker container exec -it nextcloud /bin/sh
cd /etc/apache2/sites-enabled
echo >> 000-default.conf
echo Redirect 301 /.well-known/carddav /nextcloud/remote.php/dav >> 000-default.conf
echo Redirect 301 /.well-known/caldav /nextcloud/remote.php/dav >> 000-default.conf
#4 Update Nextcloud
docker-compose pull
docker-compose up -d
docker image prune
#5.Backup and restore
likely there will be container running borg or borgmatic and cron


