Nextcloud in Docker - some pages take significant amount of time to load

Hi! I am trying to setup fresh Nextcloud instance in Docker on Raspberry Pi 4 (4GB RAM). I use docker-compose with Nextcloud fpm image and mariadb. Docker-compose configuration is borrowed from https://github.com/nextcloud/docker/tree/master/.examples/docker-compose/insecure/mariadb/fpm
This is my docker-compose file:

version: '3'

services:
  db:
    image: mariadb:10.6
    command: --transaction-isolation=READ-COMMITTED --log-bin=binlog --binlog-format=ROW
    restart: always
    volumes:
      - db:/var/lib/mysql:Z
    environment:
      - MYSQL_ROOT_PASSWORD=1234
      - MARIADB_AUTO_UPGRADE=1
      - MARIADB_DISABLE_UPGRADE_BACKUP=1

  redis:
    image: redis:alpine
    restart: always

  app:
    image: nextcloud:fpm-alpine
    restart: always
    volumes:
      - nextcloud:/var/www/html:z
    environment:
      - MYSQL_HOST=db
      - REDIS_HOST=redis
      - MYSQL_PASSWORD=123
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
    depends_on:
      - db
      - redis

  web:
    build: ./web
    restart: always
    ports:
      - 8087:80
    volumes:
      - nextcloud:/var/www/html:z,ro
    depends_on:
      - app

  cron:
    image: nextcloud:fpm-alpine
    restart: always
    volumes:
      - nextcloud:/var/www/html:z
    entrypoint: /cron.sh
    depends_on:
      - db
      - redis

volumes:
  db:
  nextcloud:

I took nginx dockerfile and configuration from https://github.com/nextcloud/docker/tree/master/.examples/docker-compose/insecure/mariadb/fpm/web and it is untouched.

After entering admin user name and password, installation takes ~3 minutes and I get timeout in a web browser, but it eventually completes in background. When I log in and navigate for example to the Apps page, it takes around 30 seconds just to show that page and then another 2 minutes to load list of installed apps. Administration / Overiew panel also takes a while to load, and “Checking for system and security issues” eventually times out with “Error occurred while checking server setup”. Interesting fact is that browsing through list of files and folders (in browser) is quite fast.
One important note: on the same device I already have existing Nextcloud installation (directly on host system, not Docker) and it works pretty well for 3 years now. So I don’t think that slowness is caused by Raspberry Pi low computing power. Also, this is how docker stats looks like while running Nextcloud in Docker (overall memory usage is 1.8 / 4 GB at that moment):

CONTAINER ID   NAME                     CPU %     MEM USAGE / LIMIT     MEM %     NET I/O           BLOCK I/O         PIDS
b384a8ac8bf2   nextcloud-test-web-1     0.00%     4.598MiB / 3.704GiB   0.12%     3.29MB / 3.62MB   156kB / 12.3kB    5
4956c84b1520   nextcloud-test-app-1     0.17%     94.79MiB / 3.704GiB   2.50%     14.4MB / 7.86MB   1.15MB / 2.97MB   4
6afaa39959bd   nextcloud-test-cron-1    0.00%     552KiB / 3.704GiB     0.01%     787kB / 485kB     4.1MB / 4.1kB     1
e42c766fca96   nextcloud-test-db-1      0.03%     83.63MiB / 3.704GiB   2.20%     4.38MB / 12.9MB   18.5MB / 12.1MB   17
baa967863689   nextcloud-test-redis-1   0.37%     3.316MiB / 3.704GiB   0.09%     1.53MB / 1.19MB   4.1kB / 115kB     6

What may be causing such slowness? How can I troubleshoot?

In my experience is the typical issue with Nextcloud is storage based, specifically the DB’s storage. You said it was working fine bare metal so It could be caused by the docker networking overhead, but it could also be IO issues from some config change.

One thing I did back when I was on a very resource constrained device was to use unix sockets. Be warned it’s can be a touch fragile as it’s not the path most traveled: https://peekread.info/tech/20220618-eking-out-some-nextcloud-performance/

For IO issues you can do a very quick check using a tool like TOP. You can sort by the status column (or use HTOP and just click it) top -o S if you see a mariadb process routinely listing D (uninterruptible sleep) most likely you’re having IO issues.

Additionally you’ll want to use your web-browsers Developers tools, Network tab and see if there is anything specifically causing issues.

If you ARE having IO issues a few things you could try:

  1. Switch to syslog for Nextcloud
    You can disable Nextcloud’s file logging by switching to syslog and setting the loglevel to 3 (warning) either via OCC command or config.php edit

php occ log:manage --level=error --backend=syslog

"log_type" => "syslog",
"logfile" => "",
"loglevel" => 3,
  1. Move your system Logs to RAM

Setup your raspberry pi to log to ram rather than disk e.g.: GitHub - azlux/log2ram: ramlog like for systemd (Put log into a ram folder)

Finally if all else fails look at this guy’s blog post: debugging nextcloud slowness He goes over using the profiler to identify where the bottle neck on his system was.

1 Like

I found the root cause. The problem was that I had DNS not accessible from my Docker containers, so I assume Nextcloud tried to make some requests to the internet and it was timing out eventually, that’s why it took so long to load some pages. I spent some time to google and finally found the answer - it was a configuration problem with PiHole on my host system. I just needed to uncomment below line in /etc/resolvconf.conf:
nameserver 127.0.0.1
Here is a detailed description - Solve DNS Resolution in Other Containers when using Docker pihole - #13 by tackin - Community How-to's - Pi-hole Userspace

Thank you @dugite-code for your suggestions, they will certainly be very useful for other people struggling with similar problems.

1 Like