权限问题:如何在Windows的Docker上设置权限以与Wordpress一起使用 [英] Permission problem: How to setup permissions on docker for windows for use with Wordpress

查看:103
本文介绍了权限问题:如何在Windows的Docker上设置权限以与Wordpress一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试上传媒体

尝试更新Wordpress

很显然,Worpress没有正确的文件权限.

Clearly, Worpress doesn't have the correct file permissions.

1.检查Docker的Windows设置并升级到WSL 2

我现在正在使用基于WSL 2的引擎,该引擎应提供

I'm using the WSL 2 based engine now, which should give full root permissions to all the files on the system. I upgraded to WPL 2 as I was first using the Hyper-V- based backend (with of course the correct file permissions setup), I tried to fix the problems by upgrading. No luck.

2.试用 chmod chown

2. Experimenting with chmod and chown

首先,我在Dockerfile中添加了 chmod -R 777/var/www/html/.据我所知,这应该赋予所有文件root权限.它没有任何作用.因此,也许我使用的是其他用户?命令 whoami 确实使我恢复了根源.
也许我做错了什么,而用户又是另一回事.因此,我添加了 chown -R www-data:www-data/var ,因为我看到www-data应该是默认的Docker用户和组.没有运气.

First, I added chmod -R 777 /var/www/html/ to the Dockerfile. As far as I know, this should give all file permissions to root. It didn't have any effect. So maybe I'm using a different user? The command whoami did give me root back though.
Maybe I did something wrong and the user is something else. So I added chown -R www-data:www-data /var, as I saw www-data should be the default Docker user and group. No luck.

仅出于乐趣,我还尝试了 chmod -R 777/var/www/html/wp-content/uploads/,只是为了更具体地说明路径.有趣的是,这给了我错误 chmod:无法访问'/var/www/html/wp-content/uploads/':没有这样的文件或目录.我确实链接了文件夹,并且可以工作(我可以在IntelliJ的文件夹结构中看到文件确实在/var/www/html中). -R 选项无论如何都应该使此递归操作,所以没关系.

Just for the fun of it, I also tried chmod -R 777 /var/www/html/wp-content/uploads/ just to be more specific in the path. Interestingly, this gave me the error chmod: cannot access '/var/www/html/wp-content/uploads/': No such file or directory. I did link the folders though and this works (I can see in the folder structure in IntelliJ the files indeed are in /var/www/html). The -R option should make this recursive anyway, so it shouldn't matter.

3.在容器运行时执行所有这些操作

所以也许是因为文件还不存在,所以我无法分配权限.因此,当容器实际运行时,我也尝试了所有这些方法.再次,没有运气.

So maybe because the files were not yet present, I could not assign permissions. So I tried all this also when the container was actually running. Again, no luck.

4.以用户 root

4. Running as user root

首先,我在 docker-compose.yml 中向服务添加了 user:root .没有运气.
然后,在 FROM php:7.4-apache 下面的Dockerfile中添加了 USER root .没有运气.

First, I added user: root to the service in my docker-compose.yml. No Luck.
Then I added USER root to the Dockerfile, just below FROM php:7.4-apache. No luck.

5.使用官方的Wordpress图片

如下所示,我将apache映像用作Dockerfile的基础.我还尝试直接从我的 docker-compose.yml 中使用wordpress:latest图像(忽略整个Dockerfile),并尝试在 FROM:wordpress:latest 顶部使用Dockerfile.两者都没有改变.

As you can see below, I'm using the apache image as a basis for my Dockerfile. I also tried using the wordpress:latest image directly from my docker-compose.yml (omitting the entire Dockerfile) and I tried using FROM: wordpress:latest on top of the Dockerfile. Both didn't change anything.

到现在,我尝试了我在互联网上可以找到的所有解决方案,但没有任何效果.疯狂的事情,所有这些在MacOS下都可以正常工作.这是我的docker文件,我希望你们能在这里为我提供帮助.

By now, I tried every solution I could find on the internet and nothing works. Crazy thing, all this works fine under MacOS. Here are my docker files, I hope u guys can help me out here.

docker-compose.yml

services:
  web:
    build:
      context: ./
      dockerfile: .docker/Dockerfile
    container_name: wolfpackvision.com
    ports:
    - "8080:80"
    volumes:
    - .:/var/www/html

Dockerfile

FROM php:7.4-apache

#USER root

RUN apt-get update
RUN docker-php-ext-install mysqli

## Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

## Install PHP-GD
RUN apt-get install -y libpng-dev libjpeg-dev libfreetype6-dev \
    && docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ \
    && docker-php-ext-install gd

## Install xdebug
RUN apt-get install --assume-yes --fix-missing git libzip-dev libmcrypt-dev openssh-client \
    libxml2-dev libpng-dev g++ make autoconf \
    && docker-php-source extract \
    && pecl install xdebug redis \
    && docker-php-ext-enable xdebug redis \
    && docker-php-source delete \
    && docker-php-ext-install pdo_mysql soap intl zip

## Configure xdebug
RUN echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.remote_port=9000" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.remote_handler=dbgp" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.remote_connect_back=0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.idekey=wolfpackvision.com" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.remote_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

## Enable mod_rewrite http://httpd.apache.org/docs/current/mod/mod_rewrite.html & mod_headers http://httpd.apache.org/docs/current/mod/mod_headers.html
RUN a2enmod rewrite \
    && a2enmod headers

## Give Full folder permissions to server
#RUN chown -R www-data:www-data /var/www/html
#RUN chmod -R 777 /var/www/html/
#RUN chmod -R 777 /var/www/html/wp-content/uploads/
#RUN chmod -R 777 /var/www/html/
#RUN chmod -R 766 /var/www/html/

## Copy php.ini over
COPY ./.docker/php/php.ini /usr/local/etc/php

## Cleanup
RUN rm -rf /tmp/*

->请不要警告我有关777的信息,我知道这一点.这完全是本地的,我永远不会在生产中使用.另外,如果我获得了许可,我可能会收紧它.首先,我希望它能正常工作.

-> Please don't go warn me about 777, I know about that. This is all strictly local and I will never use this in production. Plus, if I get the permissions working, I might tighten it. First I want it to work at all.

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.1  0.0  90652 28568 ?        Ss   11:04   0:00 apache2 -DFOREG
www-data    16  0.0  0.0  90684  8176 ?        S    11:04   0:00 apache2 -DFOREG
www-data    17  0.0  0.0  90684  8176 ?        S    11:04   0:00 apache2 -DFOREG
www-data    18  0.0  0.0  90684  8176 ?        S    11:04   0:00 apache2 -DFOREG
www-data    19  0.0  0.0  90684  8176 ?        S    11:04   0:00 apache2 -DFOREG
www-data    20  0.0  0.0  90684  8176 ?        S    11:04   0:00 apache2 -DFOREG
root        21  0.0  0.0   7640  2708 pts/0    Rs+  11:06   0:00 ps aux

我已经尝试按照PID 21、1和16的要求进行操作.所有三个结果都相同.没有文件权限.我在这里想念什么?

I already tried to do what you recommended with PID 21, 1 and 16. All three had the same result; no file permissions. What am I missing here?

推荐答案

感谢您的帮助.事实证明,这个问题与Docker无关.WordPress被配置为在我的主机文件夹结构中找到上载目录,并将其设置为/wp-content/uploads修复了所有问题.

Thanks for your help. Turns out, the issue had nothing to do with Docker. WordPress was configured to find the uploads directory within my host folder structure, setting it to /wp-content/uploads fixed everything.

仍然感谢您的帮助!

这篇关于权限问题:如何在Windows的Docker上设置权限以与Wordpress一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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