Nextcloud docker compose setup with Caddy (2024)

OK. I did a speedrun for you with the tutorial above. No editing, nothing more. That’s enough to get me to the point where I can execute the command you described at the beginning and get a direct answer that I can work with, which on the one hand makes your question obsolete and on the other hand perhaps explains the problems you’re having:

$ docker compose exec app php occ app:remove circles
circles could not be removed as it is a shipped app

Well, I couldn’t know that because I didn’t try it directly or in the past and apparently there aren’t really any topics on the subject. However, I could imagine that you don’t get this message in the first place, so I will share my speedrun. Could this become a sport? Nextcloud installation speedrun. Like the case modding overclocker competitions of old, where all the hardware had to be unpacked, installed and connected… All on time… I digress…

command list
/docker$ mkdir nextcloud_tmp
/docker$ cd nextcloud_tmp/
/docker/nextcloud_tmp$ DOCKER_PROJECT_DIR=/docker
/docker/nextcloud_tmp$ nano .env
/docker/nextcloud_tmp$ nano nextcloud.env
/docker/nextcloud_tmp$ mkdir web
/docker/nextcloud_tmp$ nano web/Caddyfile
/docker/nextcloud_tmp$ nano docker-compose.yml
/docker/nextcloud_tmp$ mkdir secrets 
echo -n "admin" > ./secrets/nextcloud_admin_user
echo -n "nextcloud" > ./secrets/postgres_db
echo -n "nextcloud" > ./secrets/postgres_user
tr -dc 'A-Za-z0-9#$%&+_' < /dev/urandom | head -c 32 | tee ./secrets/postgres_password; echo
tr -dc 'A-Za-z0-9#$%&+_' < /dev/urandom | head -c 32 | tee ./secrets/nextcloud_admin_password; echo
tr -dc 'A-Za-z0-9#$%&+_' < /dev/urandom | head -c 32 | tee ./secrets/redis_password; echo
HK%GFXfPpQ4uXSCh#Bh2xH5arK71liqw
CQ64OViSIsNtNs_kle67U6jeA3Wh%IKY
%7s2iYR8PqJmCl0qgg4dvLXfPHe9BfHv
/docker/nextcloud_tmp$ sudo mkdir /HDD/nextcloud_tmp
/docker/nextcloud_tmp$ sudo chown $USER:$USER /HDD/nextcloud_tmp
/docker/nextcloud_tmp$ DH_DATA_DIR=/HDD/nextcloud_tmp/data
/docker/nextcloud_tmp$ mkdir -p apps config data db nextcloud redis web/data web/config $DH_DATA_DIR
/docker/nextcloud_tmp$ touch redis-session.ini
/docker/nextcloud_tmp$ sudo chown 1004:1004 apps config data db nextcloud redis redis-session.ini web/data web/config web/Caddyfile $DH_DATA_DIR
/docker/nextcloud_tmp$ tree -a ${DOCKER_PROJECT_DIR}/nextcloud_tmp/
/docker/nextcloud_tmp/
├── apps
├── config
├── data
├── db
├── docker-compose.yml
├── .env
├── nextcloud
├── nextcloud.env
├── redis
├── redis-session.ini
├── secrets
│   ├── nextcloud_admin_password
│   ├── nextcloud_admin_user
│   ├── postgres_db
│   ├── postgres_password
│   ├── postgres_user
│   └── redis_password
└── web
    ├── Caddyfile
    ├── config
    └── data

11 directories, 11 files
/docker/nextcloud_tmp$ docker compose up -d
[+] Running 1/1
 ✔ web Pulled                                                                                                           2.5s 
[+] Running 6/7
 ✔ Network nextcloud_tmp_default          Created                                                                       0.2s 
 ✔ Container nextcloud_tmp-redis-1        Healthy                                                                       7.6s 
 ✔ Container nextcloud_tmp-db-1           Healthy                                                                       7.6s 
 ✔ Container nextcloud_tmp-app-1          Started                                                                       7.8s 
 ✔ Container nextcloud_tmp-web-1          Started                                                                       8.6s 
 ✔ Container nextcloud_tmp-imaginary-1    Started                                                                       8.4s 
 ⠹ Container nextcloud_tmp-notify_push-1  Starting                                                                     10.3s 
Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/var/www/html/custom_apps/notify_push/bin/x86_64/notify_push": stat /var/www/html/custom_apps/notify_push/bin/x86_64/notify_push: no such file or directory: unknown
/docker/nextcloud_tmp$ docker compose exec app php occ app:remove circles
circles could not be removed as it is a shipped app
/docker/nextcloud_tmp$ 

I did this with NEXTCLOUD_VERSION=29.0.8-fpm, next to my live system. For the sake of simplicity, I have used the user of the live instance 1004.

I do not indeed get that error, and i also tried to remove richdocuments and some other apps which should be removable (also in the gui).
I also forgot to mention i instaled nextcloud 30.0.2

Awesome guide, thank you very much @estebanium

I also got stuck on the login loop; I followed your guide along with my trusty companion, a chatgpt instance (i use duck duck go’s) and it is an invaluable asset for ruber duck debuggin this issues (sometimes). After some troubleshooting and adding NEXTCLOUD_LOG_LEVEL=debug to the nextcloud.env file I found after restarting the containers the following line:
db-1 | 2024-12-15 15:00:07.794 CET [243] FATAL: role "MYUSERNAME" does not exist

I haven’t fixed the error yet due to lack of time, but I wanted to post my findings for others that may be in the same situation I am. Some things that I found very useful while troubleshooting:

  • rubber duck debugging with chat gpt
  • having three terminals open, one with the logs for nextcloud, other with the logs for caddy and a last one to interact with both

When I get to fix the error I will report it here. Thanks to everyone for posting your findings!

Could you expand on why one would like to install imaginary and how does it differ from the previewgenerator app one can install? (And should I use one or both?)

Thanks for the guide, it was very usefull!

1 Like

The simple answer is that you don’t necessarily have to use Imaginary and can just install the Preview Generator app. If only the Preview Generator app is installed, the previews are generated with the Nextcloud on-board tools. The on-board tools work with PHP and although this is basically a great language for web applications, it is not efficient for generating preview images. That’s why Imaginary is used. And also to your question: this is not an either or, but in addition to the Preview Generator you also install Imaginary. You then specify Imaginary in the Preview Generator settings. The latter is created precisely for the use case and therefore works more efficiently and faster.

Finally:

  • Preview Generator
  • Preview Generator + Imaginary

Thanks for the reply! I ended up installing both of them.

This interests me (I tried the standard preview:generate-all and it was super slow). How can I change the app to use imaginary?

You’re welcome. It is described in “Setup imaginary”. You will likely already have a section in your config.php with OC\\Preview\\ with some file formats. You need to add these lines (by command or with an editor) to the config.php:

docker compose exec app php occ config:system:set enabledPreviewProviders 5 --value 'OC\Preview\Imaginary'
docker compose exec app php occ config:system:set preview_imaginary_url --value 'http://imaginary:9000'
# limit number of parallel jobs (adopt to your CPU core number)
docker compose exec app php occ config:system:set preview_concurrency_all --value 12
docker compose exec app php occ config:system:set preview_concurrency_new --value 8

If you want to add the entries by the commands above, you will need to pay attention to the 5. When you follow my tutorial, Imaginary will be the sixth entry (6-1=5), because we start to count on 0. I don’t know, how may entries your array already has. Using the wrong number, will result in an overwrite or an inappropriate configuration. Just for reference an example of such an array, when you are done and used the 3 for the following command:
docker compose exec app php occ config:system:set enabledPreviewProviders 3 --value 'OC\Preview\Imaginary'

'enabledPreviewProviders' =>
  array (
  0 => 'OC\\Preview\\something1',
  1 => 'OC\\Preview\\something2',
  2 => 'OC\\Preview\\something3',
  3 => 'OC\\Preview\\Imaginary',
),
'preview_imaginary_url' => 'http://imaginary:9000',

Edit:
If you set up Imaginary as it is described in the tutorial, this is really a no brainer. However, if you changed the port configuration or the hostname of the Imaginary docker container, you will need to adjust the url and port stated in the command.

1 Like

Hi @estebanium,

this is not correct what you did here:

  • OC\Preview\Imaginary
    Imaginary supports these MIME types:
    • image/bmp
    • image/x-bitmap
    • image/png
    • image/jpeg
    • image/gif
    • image/heic
    • image/heif
    • image/svg+xml
    • image/tiff
    • image/webp
    • application/illustrator
    • application/pdf (NC < 30)

and

  • OC\Preview\ImaginaryPDF (since NC 30)
    • application/pdf

so the legacy preview providers

  0 => 'OC\\Preview\\PNG',
  1 => 'OC\\Preview\\JPEG',
  2 => 'OC\\Preview\\GIF',
  3 => 'OC\\Preview\\HEIC',
  4 => 'OC\\Preview\\BMP',
  5 => 'OC\\Preview\\XBitmap',

and

  13 => 'OC\\Preview\\PDF',

… are not only no longer necessary but should also no longer be used if Imaginary is used and you want to take full advantage of its performance.

And then there is the preview provider

  9 => 'OC\\Preview\\Movie',

but there are no

  10 => 'OC\\Preview\\MKV',
  11 => 'OC\\Preview\\MP4',
  12 => 'OC\\Preview\\AVI',

preview providers. You probably thought them up yourself but they don’t exist so those lines don’t do anything.

You can read more details about preview providers here, where I explained it more in deep.

h.t.h.


Much and good luck,
ernolf

Thank you for your reply to this. I’m changing it to a more generic example, because that’s it as you already noticed. Don’t let them do stupid things.