[英]Strange “Permission denied” when trying to build C# Protobuf project inside Docker container
I have a fairly simple .net Core C# project with a .proto
file.我有一个相当简单的 .net Core C# 项目,带有
.proto
文件。 The .csproj
looks like this: .csproj
看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>My.Overview</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Protobuf Include="..\..\Protos\overview.proto" GrpcServices="Both" Link="Protos\overview.proto" />
</ItemGroup>
<Import Project="..\..\.paket\Paket.Restore.targets" />
</Project>
I have referenced this in an ASP.net Core 3.1 project, and I use Paket for resolution of dependencies.我在 ASP.net Core 3.1 项目中引用了这个,我使用 Paket 来解决依赖关系。
When I compile this from Visual Studio or dotnet build
everything works fine.当我从 Visual Studio 或
dotnet build
编译时,一切正常。
However I also want to build the service as a Docker container.但是,我还想将服务构建为 Docker 容器。 The relevant portion of the Dockerfile looks like this:
Dockerfile 的相关部分如下所示:
RUN dotnet tool install -g paket
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.dotnet/tools
COPY paket.dependencies /build/
COPY paket.lock /build/
WORKDIR /build
RUN paket install
COPY . /build
RUN dotnet publish -c Release AppThatUses.My.Overview
When I docker build
, I get this:当我
docker build
时,我得到这个:
/root/.nuget/packages/grpc.tools/2.29.0/build/_protobuf/Google.Protobuf.Tools.targets(264,5): error MSB6003: The specified task executable "/root/.nuget/packages/grpc.tools/2.29.0/tools/linux_x64/protoc" could not be run. System.ComponentModel.Win32Exception (13): Permission denied [/build/Model/Overview/Overview.csproj]
/root/.nuget/packages/grpc.tools/2.29.0/build/_protobuf/Google.Protobuf.Tools.targets(264,5): error MSB6003: at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec) [/build/Model/Overview/Overview.csproj]
/root/.nuget/packages/grpc.tools/2.29.0/build/_protobuf/Google.Protobuf.Tools.targets(264,5): error MSB6003: at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo) [/build/Model/Overview/Overview.csproj]
/root/.nuget/packages/grpc.tools/2.29.0/build/_protobuf/Google.Protobuf.Tools.targets(264,5): error MSB6003: at System.Diagnostics.Process.Start() [/build/Model/Overview/Overview.csproj]
/root/.nuget/packages/grpc.tools/2.29.0/build/_protobuf/Google.Protobuf.Tools.targets(264,5): error MSB6003: at Microsoft.Build.Utilities.ToolTask.ExecuteTool(String pathToTool, String responseFileCommands, String commandLineCommands) [/build/Model/Overview/Overview.csproj]
/root/.nuget/packages/grpc.tools/2.29.0/build/_protobuf/Google.Protobuf.Tools.targets(264,5): error MSB6003: at Microsoft.Build.Utilities.ToolTask.Execute() [/build/Model/Overview/Overview.csproj]
The command '/bin/sh -c dotnet publish -c Release AppThatUses.My.Overview' returned a non-zero code: 1
I investigated this and I saw that protoc
was not executable, so I added this line just before the dotnet publish
:我对此进行了调查,发现
protoc
不可执行,因此我在dotnet publish
之前添加了这一行:
RUN find /root/.nuget/packages -name protoc |grep linux |xargs chmod +x
Now, I get:现在,我得到:
/root/.nuget/packages/grpc.tools/2.29.0/build/_protobuf/Google.Protobuf.Tools.targets(264,5): error MSB6003: The specified task executable "/root/.nuget/packages/grpc.tools/2.29.0/tools/linux_x64/protoc" could not be run. System.ComponentModel.Win32Exception (2): No such file or directory [/build/Model/Overview/Overview.csproj]
/root/.nuget/packages/grpc.tools/2.29.0/build/_protobuf/Google.Protobuf.Tools.targets(264,5): error MSB6003: at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec) [/build/Model/Overview/Overview.csproj]
/root/.nuget/packages/grpc.tools/2.29.0/build/_protobuf/Google.Protobuf.Tools.targets(264,5): error MSB6003: at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo) [/build/Model/Overview/Overview.csproj]
/root/.nuget/packages/grpc.tools/2.29.0/build/_protobuf/Google.Protobuf.Tools.targets(264,5): error MSB6003: at System.Diagnostics.Process.Start() [/build/Model/Overview/Overview.csproj]
/root/.nuget/packages/grpc.tools/2.29.0/build/_protobuf/Google.Protobuf.Tools.targets(264,5): error MSB6003: at Microsoft.Build.Utilities.ToolTask.ExecuteTool(String pathToTool, String responseFileCommands, String commandLineCommands) [/build/Model/Overview/Overview.csproj]
/root/.nuget/packages/grpc.tools/2.29.0/build/_protobuf/Google.Protobuf.Tools.targets(264,5): error MSB6003: at Microsoft.Build.Utilities.ToolTask.Execute() [/build/Model/Overview/Overview.csproj]
I triple-checked that /build/Model/Overview/Overview.csproj
is actually there.我三重检查
/build/Model/Overview/Overview.csproj
确实存在。
What am I missing?我错过了什么?
Not a bugfix but a workaround:不是错误修复,而是一种解决方法:
dotnet tool install
are not executabledotnet tool install
的命令行工具不可执行So, here's what I did:所以,这就是我所做的:
mcr.microsoft.com/dotnet/core/sdk:3.1-buster
instead of mcr.microsoft.com/dotnet/core/sdk:3.1-alpine
mcr.microsoft.com/dotnet/core/sdk:3.1-buster
而不是mcr.microsoft.com/dotnet/core/sdk:3.1-alpine
dotnet build
: RUN chmod -Rf +x /root/.nuget/packages/grpc.tools/2.29.0/tools
dotnet build
之前添加了以下行: RUN chmod -Rf +x /root/.nuget/packages/grpc.tools/2.29.0/tools
With these changes in place, the build works.有了这些更改,构建工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.