Skip to content

Docker nginx php permissions issue

I’m just learning Docker and took on a little pet project and wondering if something is possible permission wise with docker/nginx/php. I’m attempting to convert an old IIS-Windows/php/MySql project of mine to Docker/nginx/php/mysql

I’m most of the way there and have the 3 containers linked and all is working well EXCEPT, this system has a file upload/view/delete component to it. I want the “files” stored outside of the root html folder which is “/usr/share/nginx/html” in this case.

My Linux box has a 120 gb ssd where my os and docker solution live. I have a ~9 TB raid (4 3TB drive mdadm raid 5) mounted to the system as well, and that is where I’d like to store a folder “files” and allow my docker solution to read/write to it from the PHP web interface. I can’t seem to get this to work.

I’ve added these volume maps to my docker-compose:

  - ./code:/usr/share/nginx/html
  - /mnt/md0/files:/usr/share/nginx/html/files

where “code” is my php code of course and it seems to work as far as the “files” folder being visible in the folder structure, but I can’t write to it, php permission denied error. I’ve run:

docker exec -it [myNginxContainer] chown -Rf www-data.www-data /usr/share/nginx/html/files

and that does change the actual ownership of my folder on the raid to that, but can’t write to it still from php. (doing this does work as I want it to if I put the actual “files” folder inside the code directory: /usr/share/nginx/html/ and remove the volume map in docker-compose, but I want it on the raid)

I even tried setting the folder permissions wide open:

chmod 777 /mnt/md0/files/

just so see if that would help and it doesn’t. The permissions on that folder on the raid look like this after all this:

drwxrwxrwx 2 www-data www-data  4096 Jan 17 23:41 files

seems like that should be writable?

before I tear my hair out any more, is something like this even possible? And at some point I may even want that “files” location to be a mounted network location, but at least an “external-to-my-html” folder location for now.



Consider running docker with your current host user. Here are some links that you can take a look at.:

How to run docker with current host user, when users are managed with Linux NIS (Network Information Service) Running as a host user within a Docker container

User contributions licensed under: CC BY-SA
4 People found this is helpful