2

I am trying to attach a volume to my Docker container for a PHP app that has an upload functionality.

Every time I boot up the Docker image and try to upload, I get:

Warning: move_uploaded_file(/data/projectname/uploads/CtnXkdonnhMLskxb.pdf): failed to open stream: Permission denied in /var/www/html/phpapi/upload.php on line 63

I've scoured a lot of the permissions SO articles (this, this, this, this, and this) and have found nothing that can help.

It seems my volume is attached properly. I see this when I inspect my Container:

"Mounts": [
  {
     "Type": "volume",
     "Name": "my-project-volume",
     "Source": "/var/lib/docker/volumes/my-project-volume/_data",
     "Destination": "/data/projectname/uploads",
     "Driver": "local",
     "Mode": "z",
     "RW": true,
     "Propagation": ""
  }
],

And this is my Dockerfile:

FROM node:12-alpine as build
RUN mkdir /frontend
WORKDIR /frontend
COPY ./react /frontend
RUN yarn install
RUN yarn build

FROM php:7.3-apache
COPY --from=build /frontend/build /var/www/html
COPY ./php /var/www/html/phpapi
EXPOSE 8080

My Docker run command: docker run -p 3000:80 -i -d -v my-project-volume:/data/projectname/uploads project-name:latest

When I go into my container and run ls -l on any file/folder in my container, I see that the permissions are root. For example ls -l on the data folder that's the mounted volume:

drwxr-xr-x 3 root root 4096 Dec  8 22:45 projectname

Can someone explain to me like I'm five what is happening and how to possibly fix it? I suspect it has to do with the fact that my host permissions is not the same as the container permissions... is that right?

Phil
  • 157,677
  • 23
  • 242
  • 245
cssun25
  • 381
  • 1
  • 5
  • 13
  • No, I am not sure how this is supposed to help. All my permissions are set to root, not www-data. If I were to set my `/var/www/html` folder permissions to www-data, the mounted `data` folder still has the permission of `root` and there's still a permission denied error. – cssun25 Dec 09 '20 at 20:30
  • Can you clarify what you mean? All the permissions of my folders within the container are `root`. So do I need to change it to `www-data`? And how would I go about changing the volume permissions? – cssun25 Dec 10 '20 at 00:58
  • I've just done a super simple test using docker-compose and everything works as expected. Compare [this gist](https://gist.github.com/philBrown/b8abe911e8a61ba704de822a5c83de0a) to what you've got. The only thing I'm not using is a pre-made Docker volume – Phil Dec 10 '20 at 01:44

0 Answers0