如何在WSL + VS Code与Docker容器之间设置文件所有权? [英] How do I set-up file ownership between WSL + VS Code and a Docker container?

查看:62
本文介绍了如何在WSL + VS Code与Docker容器之间设置文件所有权?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是我不知道(也不了解)如何最好地配置主机和容器之间的文件所有权.我是按行业划分的前端开发人员,所以在这里我不那么了解.

My issue is that I don't know (nor understand) how to best configure file ownership between a host and a container. I'm a front-end dev by trade so out of my depth here.

主机:运行WSL2(Ubuntu 20.04 LTS)的Windows 10.使用VS Code WSL远程扩展.

Host: Windows 10 running WSL2 (Ubuntu 20.04 LTS). Using the VS Code WSL Remote extension.

容器:运行WordPress的 php:7.4-fpm .

Container: php:7.4-fpm running WordPress.

WordPress运行正常,但是当我想通过CMS安装插件或将文件上传到媒体库时,我遇到上传的文件无法移至wp-content/uploads/2021/01.".

WordPress is running just fine but when I want to install a plugin via the CMS or upload a file to the Media library I'm met with "The uploaded file could not be moved to wp-content/uploads/2021/01.".

我认为这是因为容器已将 1000:1000 设置为文件所有者/组,但是主机列出的文件与 andrew:andrew 相同.如果我将容器更改为 www-data:www-data ,则WordPress会上载工作,但随后我将无法使用VS Code编辑文件-主机文件也将更改为 www-data:www-数据(主机上不是有效用户)-VS Code满足了以下要求:

I think this is because the container has 1000:1000 set as file owner/group but the host machine lists the same files as andrew:andrew. If I change the container to www-data:www-data then WordPress uploads work but I then cannot use VS Code to edit files - the host files also change to www-data:www-data (not a valid user on the host) - I'm met with the following from VS Code:

"无法保存'front-page.php':无法写入文件'vscode-remote://wsl+ubuntu-20.04/home/andrew/my-app/app/wp-content/themes/my-theme/theme/front-page.php'(NoPermissions(FileSystemError):错误:EACCES:权限被拒绝,打开'/home/andrew/my-app/app/wp-content/themes/my-theme/theme/front-page.php')"

"Failed to save 'front-page.php': Unable to write file 'vscode-remote://wsl+ubuntu-20.04/home/andrew/my-app/app/wp-content/themes/my-theme/theme/front-page.php' (NoPermissions (FileSystemError): Error: EACCES: permission denied, open '/home/andrew/my-app/app/wp-content/themes/my-theme/theme/front-page.php')"

我认为我使用[code] drwxr-xr-x 一直到/uploads 都正确设置了目录权限.

For what it's worth I believe my directory permissions are set-up correctly all the way down to /uploads with drwxr-xr-x.

我是否需要配置文件所有权的特定方法,以确保既可以使用WordPress上传功能,又可以在VS Code中进行文件修改?

Is there a specific way I need to configure file ownership to ensure I can both use WordPress uploads feature and also make file amends in VS Code?

谢谢!

推荐答案

已解决.在这里找到了适合我的解决方案.这样会将拥有容器中文件的用户锁定"为 www-data ,同时将原始用户 andrew 保留在主机上.

Solved. Found a solution here that worked for me. This 'locks' the user that owns the files in the container to www-data whilst preserving the original user, andrew on the host.

这篇关于如何在WSL + VS Code与Docker容器之间设置文件所有权?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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