douliu1092 2019-07-30 13:10
浏览 344

PHP mkdir():在docker卷中拒绝权限

I'm a bit lost with owner and rights inside a docker container, and I need help regarding the creation of a folder.

I'm mounting in a container a local directory images. When I launch a bash inside my container, here is the rules of my folder:

drwxrwxr-x 2 1000 1000 4096 Apr 24 21:43 images

My php code tries to create a folder:

$prodid = mysqli_insert_id($conn);
$targetDir = "../../theme/modules/products/images/".$prodid."/";
$oldumask = umask(0);
mkdir($targetDir, 0755);

But I receive this error:

Warning
: mkdir(): Permission denied in
/var/www/html/modules/product/product_new.php

I suppose the owner of this folder should be www-data:www-data (and not even sure about that), so I tried to add in my dockerfile:

FROM php:7.3-apache
...
RUN chown www-data:www-data /var/www/html/theme/modules/products/images

and my docker-compose:

version: "2"
services:
    www:
        build: .
        ports: 
            - "80:80"
        volumes:
            - ./www/.htaccess:/var/www/html/.htaccess
            - ./www/lib:/var/www/html/lib
            - ./www/modules:/var/www/html/modules
            - ./www/theme:/var/www/html/theme
            - ./www/index.php:/var/www/html/index.php
            - product-images:/var/www/html/theme/modules/products/images
        links:
            - db
        networks:
            - default
    db:
        image: mariadb:10.2
        volumes:
            - ./dump:/docker-entrypoint-initdb.d
            - mariadb-data:/var/lib/mysql
        networks:
            - default
    phpmyadmin:
        image: phpmyadmin/phpmyadmin
        links: 
            - db:db
        ports:
            - 8001:80
volumes:
    mariadb-data:
    product-images:

Rules are set, error is gone, but the folder is not created. i don't know what should be the ower/group or rights for this folder to allow php to create a folder.

When I docker-inspect the volume:

docker inspect arcadust_product-images
[
    {
        "CreatedAt": "2019-07-30T15:45:31+02:00",
        "Driver": "local",
        "Labels": null,
        "Mountpoint": "/var/lib/docker/volumes/arcadust_product-images/_data",
        "Name": "arcadust_product-images",
        "Options": {},
        "Scope": "local"
    }
]

What am I doing wrong?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程