我有一个 docker 容器配置了数据持久化到此路径:
C:\ProgramData\Persistence\data\mysql
当您开始时,一切顺利,因为没有数据(第一次运行)
一旦我开始开发,由于某种原因,我通过打开 docker-desktop 并启动容器来重新启动电脑,它就不再工作了......
我已经确定问题出在目录权限,只读属性上:
我进行了调查,并尝试通过以下方法解决:
来自 CMD:
icacls "C:\ProgramData\Persistence" /grant Everyone:(OI)(CI)F /T
形成 PowerShell:
Get-ChildItem -Path "C:\ProgramData\WSDD-Environment" -Recurse | ForEach-Object { $_.Attributes -= "ReadOnly" }
这些命令是由我的个人用户执行的,该用户具有主动管理员权限并以管理员权限运行 CMD 和 Powershell。
但是问题仍然存在...并且我找不到解决它的编程方法,这是我唯一的兴趣...
我已经验证手动更改形状属性可以解决该问题,但这不是我想要的。
更新
我一直在评估,由于某种原因,问题与docker的工作方式和目录结构......以及与第三方软件的交互有关......
问题出现的方式如下:
我想有一种方法可以从构建结构和docker/容器环境的yml本地解决问题,但到目前为止我还没有解决它......因此我诉诸于解决问题,每次发生这种情况时,您都需要在 powershell 中手动运行此脚本:
# Define the path to the directory
$directoryPath = "C:\ProgramData\Persistence"
# Get the current ACL (Access Control List) for the directory
$acl = Get-Acl $directoryPath
# Define the permission rule to grant full control to everyone
$permission = "Everyone", "FullControl", "ContainerInherit,ObjectInherit", "None", "Allow"
# Create a new access rule
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
# Add the access rule to the ACL
$acl.AddAccessRule($accessRule)
# Set the ACL for the directory
Set-Acl -Path $directoryPath -AclObject $acl
# Check if the permissions were applied successfully
Get-Acl $directoryPath
所以:
虽然此脚本解决了手动启动/检测到的问题,但这不是我期望的解决方法,我仍在寻找替代方案来防止这种情况。