Docker 上的 Wordpress:无法在已安装的卷上创建目录 [英] Wordpress on Docker: Could not create directory on mounted volume

查看:71
本文介绍了Docker 上的 Wordpress:无法在已安装的卷上创建目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是路径 /var/www/html 上 Wordpress Docker 容器中的原始文件:

Here is are the original files in the Wordpress Docker container on path /var/www/html:

$ docker exec 5b957c7b9c5ad054883694afbfb80d3c9df6707458d55011f471be0701f3890c ls -l
total 192
-rw-r--r--  1 www-data www-data   418 Sep 25  2013 index.php
-rw-r--r--  1 www-data www-data 19935 Jan  2 18:51 license.txt
-rw-r--r--  1 www-data www-data  7433 Jan 11 17:46 readme.html
-rw-r--r--  1 www-data www-data  5447 Sep 27  2016 wp-activate.php
drwxr-xr-x  9 www-data www-data  4096 May 16 21:50 wp-admin
-rw-r--r--  1 www-data www-data   364 Dec 19  2015 wp-blog-header.php
-rw-r--r--  1 www-data www-data  1627 Aug 29  2016 wp-comments-post.php
-rw-r--r--  1 www-data www-data  2764 May 29 22:19 wp-config-sample.php
-rw-r--r--  1 www-data www-data  3148 May 29 22:19 wp-config.php
drwxr-xr-x  4 www-data www-data  4096 May 16 21:50 wp-content
-rw-r--r--  1 www-data www-data  3286 May 24  2015 wp-cron.php
drwxr-xr-x 18 www-data www-data 12288 May 16 21:50 wp-includes
-rw-r--r--  1 www-data www-data  2422 Nov 21  2016 wp-links-opml.php
-rw-r--r--  1 www-data www-data  3301 Oct 25  2016 wp-load.php
-rw-r--r--  1 www-data www-data 33939 Nov 21  2016 wp-login.php
-rw-r--r--  1 www-data www-data  8048 Jan 11 05:15 wp-mail.php
-rw-r--r--  1 www-data www-data 16255 Apr  6 18:23 wp-settings.php
-rw-r--r--  1 www-data www-data 29896 Oct 19  2016 wp-signup.php
-rw-r--r--  1 www-data www-data  4513 Oct 14  2016 wp-trackback.php
-rw-r--r--  1 www-data www-data  3065 Aug 31  2016 xmlrpc.php

我正在尝试使用挂载的 Docker 卷启动 Wordpress 容器,以便能够持久存储自定义文件:

I am trying to start the Wordpress container with a mounted Docker volume to be able to store the custom files persistently:

$ sudo docker run -p 80:80 --link some-mysql:mysql  -v /var/www:/var/www/html --name docker-wordpress -d wordpress

问题是,即使在 /var/www 中精确复制本地文件的所有权和权限:

The problem is that even when exactly replicating the ownership and priviledges on local files in /var/www:

$ sudo chown -R www-data:www-data /var/www
$ sudo find /var/www/ -type d -exec chmod 755 {} \;
$ sudo find /var/www/ -type f -exec chmod 644 {} \;

在容器内运行 Wordpress 时,我仍然收到此类错误:

I am still getting an error of this kind, when running Wordpress inside the container:

无法创建目录

如何正确设置权限以确保 Wordpress 能够写入已挂载的 Docker 卷?

How to set the privileges properly to make sure Wordpress is able to write into the mounted Docker volume?

推荐答案

查看您的错误消息,我得出的结论是您正在尝试安装插件或更新 wordpress 本身

Looking at your error message i come to the conclusion that you are trying to install a plugin or update wordpress itself

这个问题有点难以弄清楚.

This issue is slightly tricky to figure out.

执行 chown -R www-data:www-data/var/www 设置正确的用户:组权限应该在技术上解决它,但是..

executing chown -R www-data:www-data /var/www to set correct user:group permissions should technically solve it, however ..

在新的 wordpress 上安装 upload &plugins 文件夹尚不存在,因此当安装程序尝试创建 plugins/subfolder 时,它会抛出错误.

On a new wordpress install the upload & plugins folder does not yet exist and therefore when installer trying to create a plugins/subfolder it will throw the error.

一旦掌握了这个问题,解决它就很容易了.

Fixing this issue is however quite easy once grasping it.

在您的 .Docker 文件中,在任何 [CMD] 命令之前添加以下内容.

in your .Docker file add following towards the very end but before any [CMD] command.

运行 mkdir/var/www/html/wp-content/plugins
运行 mkdir/var/www/html/wp-content/uploads
运行 chown -R www-data:www-data/var/www
RUN find/var/www/-type d -exec chmod 0755 {} \;
RUN find/var/www/-type f -exec chmod 644 {} \;

ssh 到您的 docker 容器
docker exec -it /bin/bash

ssh in to your docker container
docker exec -it <container_name> /bin/bash

如果您不知道容器名称,请使用
docker ps

If you don't know the container name find it with
docker ps

只需运行与上述示例相同的命令
$ mkdir/var/www/html/wp-content/plugins
$ mkdir/var/www/html/wp-content/uploads
$ chown -R www-data:www-data/var/www
$ find/var/www/-type d -exec chmod 0755 {} \;
$ find/var/www/-type f -exec chmod 644 {} \;

Simply run same commands as in example above
$ mkdir /var/www/html/wp-content/plugins
$ mkdir /var/www/html/wp-content/uploads
$ chown -R www-data:www-data /var/www
$ find /var/www/ -type d -exec chmod 0755 {} \;
$ find /var/www/ -type f -exec chmod 644 {} \;

这篇关于Docker 上的 Wordpress:无法在已安装的卷上创建目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆