nextcloud / nextcloud/docker

Automatically set directory ownership when using NEXTCLOUD_DATA_DIR

Open
#1,396 13 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

1. To develop data persistence docs enhancement feature: auto config (environment variables) needs review
Dominant language
Shell
Stars
7.4k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

I'm using the nextcloud docker image (nc version 20.0.6.1). It seems to have support for setting NEXTCLOUD_DATA_DIR, but there are issues.

Snippet of my docker-compose file:

  app:
    image: nextcloud:fpm-alpine
    restart: unless-stopped
    volumes:
      - nextcloud:/var/www/html
      - nc_data:/opt/nextcloud/data
    environment:
      - MYSQL_HOST=db
      - REDIS_HOST=redis
      - OVERWRITEWEBROOT=/nextcloud
      - NEXTCLOUD_DATA_DIR=/opt/nextcloud/data
    env_file:
      - db.env
    depends_on:
      - db
      - redis
Issue 1: Permissions on NEXTCLOUD_DATA_DIR are not set

If you try this, nextcloud installation (with browser button 'Install') does not work, because 'www-data:root' has no permission to write to /opt/nextcloud/data.

Workaround

Before starting the installation process in the browser, log into the container and fix the permissions, i.e.

$ podman exec -it <nextcloud-container-id> sh
/var/www/html # chown -R www-data:root /opt/nextcloud/data/

It would be great if the /entrypoint.sh script would set the permissions appropriate.

Issue 2: appdata directory at NEXTCLOUD_DATA_DIR location must be served

If I use the workaround above to complete the installation process, I could log in, but there are missing resources. This is because after the install, my NEXTCLOUD_DATA_DIR (/opt/nextcloud/data) looks like this:

# ls -l /opt/nextcloud/data/
total 12
drwxr-xr-x    4 www-data www-data        32 Feb  7 08:18 admin
drwxr-xr-x    8 www-data www-data        89 Feb  7 08:18 appdata_ocvkg7lyrl56
-rw-r--r--    1 www-data www-data         0 Feb  7 08:17 index.html
-rw-r-----    1 www-data www-data      9736 Feb  7 08:18 nextcloud.log

# ls -l /opt/nextcloud/data/appdata_ocvkg7lyrl56/
total 0
drwxr-xr-x    2 www-data www-data        23 Feb  7 08:17 appstore
drwxr-xr-x    3 www-data www-data        19 Feb  7 08:18 avatar
drwxr-xr-x   11 www-data www-data       147 Feb  7 08:43 css
drwxr-xr-x    3 www-data www-data        19 Feb  7 08:18 dashboard
drwxr-xr-x    4 www-data www-data        34 Feb  7 08:18 js
drwxr-xr-x    8 www-data www-data        60 Feb  7 08:18 preview

# ls -l /opt/nextcloud/data/appdata_ocvkg7lyrl56/css/
total 0
drwxr-xr-x    2 www-data www-data        97 Feb  7 08:18 activity
drwxr-xr-x    2 www-data www-data       215 Feb  7 08:18 core
drwxr-xr-x    2 www-data www-data       109 Feb  7 08:18 dashboard
drwxr-xr-x    2 www-data www-data        55 Feb  7 08:18 icons
drwxr-xr-x    2 www-data www-data       100 Feb  7 08:18 notifications
drwxr-xr-x    2 www-data www-data       106 Feb  7 08:43 settings
drwxr-xr-x    2 www-data www-data        97 Feb  7 08:18 text
drwxr-xr-x    2 www-data www-data       103 Feb  7 08:18 theming
drwxr-xr-x    2 www-data www-data       130 Feb  7 08:18 user_status

# ls -l /opt/nextcloud/data/appdata_ocvkg7lyrl56/js
total 0
drwxr-xr-x    2 www-data www-data        97 Feb  7 08:18 activity
drwxr-xr-x    2 www-data www-data       118 Feb  7 08:18 core

There are a bunch of files inside /opt/nextcloud/data/appdata_ocvkg7lyrl56 that needs to be served by the web server (i.e. nginx in my case). However, the whole idea of using NEXTCLOUD_DATA_DIR is to harden the installation (with better protecting user data).

Perhaps it is possible to move stuff under /opt/nextcloud/data/appdata_<random_id> to the nextcloud directory (/var/www/html for nextcloud-docker) in the /entrypoint.sh script?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading /entrypoint.sh and trace how NEXTCLOUD_DATA_DIR is handled during container startup and installation. Reproduce the docker-compose setup with the mounted data volume, then verify ownership and whether appdata resources remain usable when the data directory is outside /var/www/html. Done means both reported installation and missing-resource cases are addressed without requiring the manual chown workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, nginx, shell
Domain
devops, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.