docker - Docker 容器中的 dotnet ef 数据库更新失败并出现错误权限
问题描述
我正在尝试构建一个将在我的生产环境中运行 EF Core 迁移的 docker 映像,但我很难弄清楚如何配置访问权限,以便我与具有最小权限但仍然足够的用户一起运行执行任务。我的Dockerfile
样子是这样的:
FROM microsoft/dotnet:2.1-sdk-alpine3.7
# Create an app-specific user, to avoid running as root
RUN addgroup -g 1001 -S app && \
adduser -u 1001 -S app -G app
USER app
# Connection string is set when starting the container
ENV ConnectionStrings__MyContext = "<set the ConnectionStrings__MyContext environment variable!>"
# Build the app inside the home dir of the app user
WORKDIR /home/app/db-update
COPY MyApp.csproj .
RUN dotnet restore
COPY . .
RUN dotnet build --configuration Release
# Apply migrations using the SDK
CMD dotnet ef database update
但是,当我尝试从此文件构建映像时,dotnet restore
命令失败并出现以下错误:
Step 8/11 : RUN dotnet restore
---> Running in 8df166ad5be0
Restoring packages for /home/app/db-update/MyApp.csproj...
Restoring packages for /home/app/db-update/MyApp.csproj...
Installing System.Threading.Tasks.Extensions 4.5.0.
Installing System.Memory 4.5.0.
... a lot of packages ...
Installing Microsoft.Extensions.Configuration.AzureKeyVault 2.1.0.
Generating MSBuild file /home/app/db-update/obj/MyApp.csproj.nuget.g.props.
/usr/share/dotnet/sdk/2.1.302/NuGet.targets(114,5): error : Access to the path '/home/app/db-update/obj' is denied. [/home/app/db-update/MyApp.csproj]
/usr/share/dotnet/sdk/2.1.302/NuGet.targets(114,5): error : Permission denied [/home/app/db-update/MyApp.csproj]
ERROR: Service 'notes-db_migrations' failed to build: The command '/bin/sh -c dotnet restore' returned a non-zero code: 1
它似乎对我选择的工作目录没有帮助(例如/db-update
或/home/app/db-update
),无论如何我都会收到相同的权限被拒绝错误。
配置它的正确方法是什么?
解决方案
推荐阅读
- reactjs - Uncaught Invariant Violation:当使用 InfoWindow 渲染地图时,对象作为 React 子级无效(发现:带有键 {} 的对象)
- swift - 如何从服务器下载图像并快速显示淡入淡出动画?
- python-3.x - 如何通过将方法名称传递给函数参数来调用python的get或请求库的任何方法?
- c# - 为什么实体框架不为我的第二个查询使用 ReadUncommitted?
- java - jar 文件打不开
- css - 如何正确定位径向渐变背景?
- macos - 如何在 macOS mojave 的终端中为文件扩展名设置默认应用程序?
- reactjs - 如何将 api 中的数组作为道具传递给另一个组件
- angular - Jest for Angular cobertura 文件重命名
- python - 如何使用 filediscriptor 3 将音频流式传输到对话流