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

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

问题描述

正在尝试上传媒体

正在尝试更新 Wordpress

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

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

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

我现在正在使用基于 WSL 2 的引擎,它应该提供 对系统上所有文件的完全 root 权限.我在第一次使用基于 Hyper-V 的后端时升级到 WPL 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.试验 chmodchown

2. Experimenting with chmod and chown

首先,我将 chmod -R 777/var/www/html/ 添加到 Dockerfile.据我所知,这应该将所有文件权限授予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: cannot access '/var/www/html/wp-content/uploads/': No such file or directory.我确实链接了这些文件夹,这很有效(我可以在 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

首先,我在 docker-compose.yml 中将 user: root 添加到服务中.没有运气.
然后我将 USER root 添加到 Dockerfile,就在 FROM php:7.4-apache 下方.没有运气.

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:latestDocker 文件.两者都没有改变任何东西.

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.

感谢您的帮助!

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

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