我尝试从一个Dockerfile构建一个映像。问题是它找不到Messages类库,这意味着我必须执行类似COPY ["src/MarketData.Subscriber/MarketData.Subscriber.csproj", "MarketData.Subscriber/"] COPY ["src/MarketData.Messages/MarketData.Messages.csproj", "MarketData.Messages/"]
的操作,但是当我在WORKDIR下添加这些类库时,COPY失败。我该如何解决这个问题?
文件夹结构
.
+---src
| +---MarketData.Api
| +---MarketData.Messages
| +---MarketData.Subscriber
| +---Dockerfile
+---MarketData.sln
停靠文件
# Stage 1 - Build
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS builder
WORKDIR /app/src
# Restore
COPY *.csproj .
RUN dotnet restore -r linux-x64
# Build
COPY . .
RUN dotnet publish -c Release -o /app/publish -r linux-x64 --no-self-contained --no-restore
# Stage 2 - Publish
FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /app
RUN addgroup --system --gid 101 app \
&& adduser --system --ingroup app --uid 101 app
COPY --from=builder --chown=app:app /app/publish .
USER app
ENTRYPOINT ["./MarketData.Subscriber"]
错误
[+] Building 4.0s (14/15)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 589B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 35B 0.0s
=> [internal] load metadata for mcr.microsoft.com/dotnet/sdk:7.0 0.4s
=> [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:7.0 0.0s
=> [stage-1 1/4] FROM mcr.microsoft.com/dotnet/aspnet:7.0 0.0s
=> [builder 1/6] FROM mcr.microsoft.com/dotnet/sdk:7.0@sha256:66a16cd71b82a2df577e52dfd01d8039ed4c20e3f17fca31b2fb3cf5929eaa7f 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 650B 0.0s
=> CACHED [stage-1 2/4] WORKDIR /app 0.0s
=> CACHED [stage-1 3/4] RUN addgroup --system --gid 101 app && adduser --system --ingroup app --uid 101 app 0.0s
=> CACHED [builder 2/6] WORKDIR /app/src 0.0s
=> CACHED [builder 3/6] COPY *.csproj . 0.0s
=> CACHED [builder 4/6] RUN dotnet restore -r linux-x64 0.0s
=> CACHED [builder 5/6] COPY . . 0.0s
=> ERROR [builder 6/6] RUN dotnet publish -c Release -o /app/publish -r linux-x64 --no-self-contained --no-restore 3.5s
------
> [builder 6/6] RUN dotnet publish -c Release -o /app/publish -r linux-x64 --no-self-contained --no-restore:
#14 0.567 MSBuild version 17.4.0-preview-22368-02+c8492483a for .NET
#14 1.270 /usr/share/dotnet/sdk/7.0.100-preview.7.22377.5/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(219,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy [/app/src/MarketData.Subscriber.csproj]
#14 1.532 /usr/share/dotnet/sdk/7.0.100-preview.7.22377.5/Microsoft.Common.CurrentVersion.targets(2082,5): warning : The referenced project '../MarketData.Messages/MarketData.Messages.csproj' does not exist. [/app/src/MarketData.Subscriber.csproj]
#14 3.416 /app/src/Actors/FtxSubscriptionGrain.cs(2,7): error CS0246: The type or namespace name 'Google' could not be found (are you missing a using directive or an assembly reference?) [/app/src/MarketData.Subscriber.csproj]
#14 3.416 /app/src/Actors/FtxSubscriptionGrain.cs(3,18): error CS0234: The type or namespace name 'Messages' does not exist in the namespace 'MarketData' (are you missing an assembly reference?) [/app/src/MarketData.Subscriber.csproj]
#14 3.416 /app/src/Actors/FtxSubscriptionGrain.cs(5,7): error CS0246: The type or namespace name 'Proto' could not be found (are you missing a using directive or an assembly reference?) [/app/src/MarketData.Subscriber.csproj]
#14 3.416 /app/src/Actors/FtxSubscriptionGrain.cs(6,7): error CS0246: The type or namespace name 'Proto' could not be found (are you missing a using directive or an assembly reference?) [/app/src/MarketData.Subscriber.csproj]
#14 3.416 /app/src/ActorSystemConfiguration.cs(1,18): error CS0234: The type or namespace name 'Messages' does not exist in the namespace 'MarketData' (are you missing an assembly reference?) [/app/src/MarketData.Subscriber.csproj]
#14 3.416 /app/src/ActorSystemConfiguration.cs(3,7): error CS0246: The type or namespace name 'Proto' could not be found (are you missing a using directive or an assembly reference?) [/app/src/MarketData.Subscriber.csproj]
#14 3.416 /app/src/ActorSystemConfiguration.cs(4,7): error CS0246: The type or namespace name 'Proto' could not be found (are you missing a using directive or an assembly reference?) [/app/src/MarketData.Subscriber.csproj]
#14 3.417 /app/src/ActorSystemConfiguration.cs(5,7): error CS0246: The type or namespace name 'Proto' could not be found (are you missing a using directive or an assembly reference?) [/app/src/MarketData.Subscriber.csproj]
#14 3.417 /app/src/ActorSystemConfiguration.cs(6,7): error CS0246: The type or namespace name 'Proto' could not be found (are you missing a using directive or an assembly reference?) [/app/src/MarketData.Subscriber.csproj]
#14 3.417 /app/src/ActorSystemConfiguration.cs(7,7): error CS0246: The type or namespace name 'Proto' could not be found (are you missing a using directive or an assembly reference?) [/app/src/MarketData.Subscriber.csproj]
#14 3.417 /app/src/ActorSystemConfiguration.cs(8,7): error CS0246: The type or namespace name 'Proto' could not be found (are you missing a using directive or an assembly reference?) [/app/src/MarketData.Subscriber.csproj]
#14 3.417 /app/src/ActorSystemConfiguration.cs(9,7): error CS0246: The type or namespace name 'Proto' could not be found (are you missing a using directive or an assembly reference?) [/app/src/MarketData.Subscriber.csproj]
#14 3.417 /app/src/ActorSystemHostedService.cs(1,7): error CS0246: The type or namespace name 'Proto' could not be found (are you missing a using directive or an assembly reference?) [/app/src/MarketData.Subscriber.csproj]
#14 3.417 /app/src/ActorSystemHostedService.cs(2,7): error CS0246: The type or namespace name 'Proto' could not be found (are you missing a using directive or an assembly reference?) [/app/src/MarketData.Subscriber.csproj]
#14 3.417 /app/src/Actors/FtxSubscriptionGrain.cs(10,39): error CS0246: The type or namespace name 'FtxSubscriptionBase' could not be found (are you missing a using directive or an assembly reference?) [/app/src/MarketData.Subscriber.csproj]
#14 3.417 /app/src/Actors/FtxSubscriptionGrain.cs(12,22): error CS0246: The type or namespace name 'ClusterIdentity' could not be found (are you missing a using directive or an assembly reference?) [/app/src/MarketData.Subscriber.csproj]
#14 3.417 /app/src/Actors/FtxSubscriptionGrain.cs(18,9): error CS0246: The type or namespace name 'IContext' could not be found (are you missing a using directive or an assembly reference?) [/app/src/MarketData.Subscriber.csproj]
#14 3.417 /app/src/Actors/FtxSubscriptionGrain.cs(19,9): error CS0246: The type or namespace name 'ClusterIdentity' could not be found (are you missing a using directive or an assembly reference?) [/app/src/MarketData.Subscriber.csproj]
#14 3.417 /app/src/ActorSystemHostedService.cs(8,22): error CS0246: The type or namespace name 'ActorSystem' could not be found (are you missing a using directive or an assembly reference?) [/app/src/MarketData.Subscriber.csproj]
#14 3.417 /app/src/ActorSystemHostedService.cs(11,37): error CS0246: The type or namespace name 'ActorSystem' could not be found (are you missing a using directive or an assembly reference?) [/app/src/MarketData.Subscriber.csproj]
#14 3.417 /app/src/Actors/FtxSubscriptionGrain.cs(36,36): error CS0246: The type or namespace name 'SubscriptionRequest' could not be found (are you missing a using directive or an assembly reference?) [/app/src/MarketData.Subscriber.csproj]
#14 3.417 /app/src/Actors/FtxSubscriptionGrain.cs(51,38): error CS0246: The type or namespace name 'SubscriptionRequest' could not be found (are you missing a using directive or an assembly reference?) [/app/src/MarketData.Subscriber.csproj]
#14 3.417 /app/src/Actors/FtxSubscriptionGrain.cs(57,26): error CS0246: The type or namespace name 'SubscriptionStatus' could not be found (are you missing a using directive or an assembly reference?) [/app/src/MarketData.Subscriber.csproj]
------
executor failed running [/bin/sh -c dotnet publish -c Release -o /app/publish -r linux-x64 --no-self-contained --no-restore]: exit code: 1
3条答案
按热度按时间bwleehnv1#
保持你的dockerfile在解决方案级别。那么只有它才能找到src文件夹。
你的文件夹结构应该看起来像这样。
并且还将相应的拷贝项目文件命令添加到DockerFile。
希望能有所帮助。
6uxekuva2#
在visual studio中,可以将docker文件移动到一个后面的文件夹中。例如,将folder 1/folder 2/docerfile移动到folder 1/docerfile并生成图像。
对我很有效。
voase2hg3#
多亏了Cisien,这个问题得到了修复。这是由于我运行构建的方式。
它应该从根目录和
docker build . -f src/Dockerfile
运行。".“表示构建上下文,或者换句话说,表示Docker构建过程可用的父目录。C:\用户\用户\桌面\市场数据〉Docker构建-t市场数据:1.0 -f ./src/市场数据.订阅者/Docker文件.
希望对其他人有帮助。
停靠文件