允许WordPress写入对Docker挂载文件夹的访问权限

问题描述 投票:2回答:2

我有一个Docker设置,可以很好地与Ubuntu,Nginx,PHP-FPM和MySQL配合使用。

WordPress可以写入uploads文件夹,我可以在线编辑模板,但是当我尝试升级WordPress或插件时,它失败了:

打开更新包......

无法创建目录:wordpress

安装失败

我有chmod 777整个WordPress文件夹,所以我不确定这是Docker还是WordPress相关。我还检查了各种日志,但我发现的唯一相关行是:

192.168.59.3 - - [01 / Oct / 2014:14:16:58 +0000]“POST /wp-admin/update-core.php?action=do-core-upgrade HTTP / 1.1”200 5576“/ wp- admin / update-core.php“”Mozilla / 5.0(Macintosh; Intel Mac OS X 10_10_0)AppleWebKit / 537.36(KHTML,与Gecko一样)Chrome / 37.0.2062.124 Safari / 537.36“

以下是我创建Docker环境的方法:

brew install docker boot2docker
boot2docker init
# Allow VM access to our space
curl http://static.dockerfiles.io/boot2docker-v1.2.0-virtualbox-guest-additions-v4.3.14.iso > ~/.boot2docker/boot2docker.iso
VBoxManage sharedfolder add boot2docker-vm -name home -hostpath /Users
boot2docker up

以下是我启动容器的方法:

docker run -p 80:80 --name wp -d -v ~/wordpress:/mnt/www:rw wp

这是Nginx配置:

server {

    listen   80; ## listen for ipv4; this line is default and implied
    listen   [::]:80 default ipv6only=on; ## listen for ipv6

    root /mnt/www;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name localhost;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to index.html
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/www;
    }

    # pass the PHP scripts to FastCGI server
    #
    location ~ \.php$ {
    try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

}
wordpress macos docker boot2docker
2个回答
0
投票

似乎需要一些黑客能够像root用户一样以其他用户的身份写入已装入的卷。见https://github.com/boot2docker/boot2docker/issues/581


0
投票

我无法访问您的Dockerfile,但是对于docker和WordPress安装插件,模板或创建文件夹的权限问题,您可以在Dockerfile中使用命令COPY和chown参数。如下所示:

COPY [--chown=<user>:<group>] <src>... <dest>

例如,在我的代码runnig wordpress中,我使用:

COPY --chown=www-data:www-data ./app/ /var/www/html/ 

但是你需要使用最后一个版本的Docker来使用chown参数。很多人得到未知的chown参数,这是因为Docker版本。所以在使用chown之前我指示更新你的Docker。

关于COPY命令的Docker参考:https://docs.docker.com/engine/reference/builder/#copy

关于权限的Wordpress参考和www-data用户:https://codex.wordpress.org/Changing_File_Permissions

© www.soinside.com 2019 - 2024. All rights reserved.