Next Cloud (docker) - "Cannot create or write into the data directory" eurror

in my ubuntu server I run a docker container using this command:

sudo docker run -it --name next-cloud-01 -d -p 8080:80 -v "/media/usr/dati:/var/www/html/data/usr/files" nextcloud

/media/usr/dati is a mount point for my sdb1 HD, and /var/www/html/data/usr/files is where Next Cloud saves the user data. I specified this volume because I want that Next Cloud manages all the data using my sdb1 HD.

unfortunately when I try to configure Next Cloud, something wrong happens, and from the login web page, I can’t do anything (see the attached screenshot).

error

if I don’t use the -v option this error doesn’t exist, so I think that, maybe, the issue is something like permissions, … it seems that Next Cloud is not able to write on sdb1 HD, but I don’t know why. how can I solve thi issue?

For addressing the “Cannot create or write into the data directory” issue with Nextcloud in Docker:

  1. Check Directory Permissions: Ensure that the directory on the host you’re linking to the Docker container has the correct permissions. Use ls -l /path/to/directory to view permissions and adjust with chmod and chown if necessary, so the Docker process has access.

  2. Use --user Flag in Docker: Start the container with the --user flag to specify the User ID (UID) and Group ID (GID) for the container process. This aligns the container’s permissions with those of the directory owner. Example: docker run --user $(id -u):$(id -g) ... to run the container with the current user’s UID and GID.

all users should be not have issues abut reading and writing my local folder path doesn’t have restrictions:

usr@server:/media/usr$ ls -l
total 8
drwxrwxrwx 1 root root 4096 Dec 12 13:35 dati

I also tried to follow your second advice modifying the docker command in this way, but, it didn’t work (i have the same issue ath the login):

sudo docker run -it --user $(id -u):$(id -g) --name next-cloud-01 -d -p 8080:80 -v “/media/andrea/dati:/var/www/html/data/usr/files” nextcloud

with my user I can read and write on /media/usr/dati so what is the issue?

hi @TurboC welcome to the community :handshake:

and like always - search helps - lot of issues have been discussed already!

this is not the right mount destination. From the docs you see

/var/www/html/ folder where all Nextcloud data lives

you want to persist more than files only e.g. config is essential :wink:

Nextcloud runs by default with user 33:33 I would recommend to assign this user and correct permissions (folders:750, files: 640) to all data mounted into NC container. Newer versions can run with a different UID but this requires more tweaking.

You’ll want to manage folder permissions to match www-data and use fstab to mount your disk before docker accesses it as a volume