【问题标题】:Allow WordPress write access to Docker mounted folder允许 WordPress 对 Docker 安装的文件夹进行写访问
【发布时间】:2023-03-21 15:07:01
【问题描述】:

我有一个与 Ubuntu、Nginx、PHP-FPM 和 MySQL 配合使用的 Docker 设置。

WordPress 可以写入上传文件夹,我可以在线编辑模板,但是当我尝试升级 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;英特尔 Mac OS X 10_10_0)AppleWebKit/537.36(KHTML,如 壁虎)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


    【解决方案1】:

    似乎需要一些技巧才能以除 root 以外的其他用户身份写入已安装的卷。见https://github.com/boot2docker/boot2docker/issues/581

    【讨论】:

      【解决方案2】:

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

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

      例如,在我运行 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

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

      【讨论】:

        猜你喜欢
        • 2011-12-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-26
        • 2014-02-13
        • 1970-01-01
        • 1970-01-01
        • 2013-07-15
        相关资源
        最近更新 更多