Docker: Permission denied when PHP upload file to mounted data volume

主宰稳场 提交于 2021-02-08 04:30:11

问题


I'm using docker quickstart terminal on Win10.

Client:
 Version:      17.06.0-ce, 
 API version:  1.30
 Go version:   go1.8.3
 Git commit:   02c1d87
 Built:        Fri Jun 23 21:30:30 2017
 OS/Arch:      windows/amd64

I have a simple document upload php script that saves an uploaded document to a file location called '/uploads'.

I want to make the '/uploads' folder a volume attached to the php:apache container, so i can easily share the contents with the python back-end.

I'm using the following docker-compose.yml file to build a web service with a python back-end. Note: The php works on the php:apache environment without the volume.

$ docker volume create fileul --opt o=uid=197609,gid=0

version: '3.2'

services:
  Python_app:
    build: ./product
    volumes:
      - ./product:/usr/src/app
ports:
  - 5001:80

website:
    image: php:apache
    volumes:
      - ./website:/var/www/html
      - type: volume
        source: fileuld
        target: /var/www/html/uploads
        read_only: false
    ports:
      - 5000:80
    depends_on:
      - Python_app

volumes:
  fileuld:

I get a permission error on the web service when I try to upload a document to the attached volume fileuld. failed to open stream: Permission denied in /var/www/html/upload.php

I have read some other stackoverflow posts on this and they talk about uid and gid and i have tried using :

$ls -ls

Which gives the following:

 4 -rw-r--r-- 1 ASUSNJHOME 197609 343 Sep 23 14:49 docker-compose.yml
32 drwxr-xr-x 1 ASUSNJHOME 197609   0 Sep 22 07:10 product/
 0 drwxr-xr-x 1 ASUSNJHOME 197609   0 Sep 23 15:38 volume-example/
 0 drwxr-xr-x 1 ASUSNJHOME 197609   0 Sep 22 21:32 website/

But i can't work out how to have the volume able to accept a document getting written into or how to change the permissions of it when it is being created from the docker-compose file.

Can anyone point me in the right direction?

Thanks

Michael

来源:https://stackoverflow.com/questions/46378832/docker-permission-denied-when-php-upload-file-to-mounted-data-volume

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!