Das Erstellen von Dockerfile im ASP.NET -Kernprojekt schlägt bei der Ausführung von Dotnet -Veröffentlichungen fehlC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Das Erstellen von Dockerfile im ASP.NET -Kernprojekt schlägt bei der Ausführung von Dotnet -Veröffentlichungen fehl

Post by Anonymous »

Ich möchte Kafka, Zookeeper und meine 2 Dienste in verschiedenen Containern betreiben. Ich muss lernen, wie Message Broker funktioniert. Aber ich habe in dieser Situation geblieben. Beim Ausführen von Docker -Compose -D erhalte ich diesen Fehler: < /p>

Code: Select all

 > [reportservice publish 1/1] RUN dotnet publish "./ReportService.csproj" -c Release -o /app/publish /p:UseAppHost=false:
1.013   Determining projects to restore...
1.350   All projects are up-to-date for restore.
2.130   DirectoryService -> /src/DirectoryService/bin/Release/net9.0/DirectoryService.dll
4.383 /src/ReportService/Migrations/20250412141416_initial.cs(9,26): warning CS8981: The type name 'initial' only contains lower-cased ascii characters. Such names may become reserved for the language. [/src/ReportService/ReportService.csproj]
4.383 /src/ReportService/Migrations/20250412141416_initial.Designer.cs(16,19): warning CS8981: The type name 'initial' only contains lower-cased ascii characters. Such names may become reserved for the language. [/src/ReportService/ReportService.csproj]
4.383 /src/ReportService/Models/Report.cs(10,23): warning CS8618: Non-nullable property 'Location' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable. [/src/ReportService/ReportService.csproj]
4.383 /src/ReportService/Services/ReportService.cs(28,36): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. [/src/ReportService/ReportService.csproj]
4.590   ReportService -> /src/ReportService/bin/Release/net9.0/ReportService.dll
4.802 /usr/share/dotnet/sdk/9.0.203/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.ConflictResolution.targets(112,5): error NETSDK1152: Found multiple publish output files with the same relative path: /src/DirectoryService/appsettings.Development.json, /src/ReportService/appsettings.Development.json, /src/DirectoryService/appsettings.json, /src/ReportService/appsettings.json.  [/src/ReportService/ReportService.csproj]
------
failed to solve: process "/bin/sh -c dotnet publish \"./ReportService.csproj\" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false" did not complete successfully: exit code: 1
< /code>
Hier ist meine Docker-Compose-Datei: < /p>
version: '3.8'

services:
zookeeper:
image: confluentinc/cp-zookeeper:7.5.0
container_name: zookeeper
ports:
- "2181:2181"
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
networks:
- app-network

kafka:
image: confluentinc/cp-kafka:7.5.0
container_name: kafka
ports:
- "9092:9092"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
depends_on:
- zookeeper
networks:
- app-network

directoryservice:
build:
context: .
dockerfile: DirectoryService/Dockerfile
container_name: directoryservice
ports:
- "5000:80"
environment:
- ASPNETCORE_ENVIRONMENT=Development
- KAFKA_BOOTSTRAP_SERVERS=kafka:9092
depends_on:
- kafka
networks:
- app-network
restart: always

reportservice:
build:
context: .
dockerfile: ReportService/Dockerfile
container_name: reportservice
ports:
- "5001:80"
environment:
- ASPNETCORE_ENVIRONMENT=Development
- KAFKA_BOOTSTRAP_SERVERS=kafka:9092
depends_on:
- kafka
networks:
- app-network
restart: always

networks:
app-network:
driver: bridge
< /code>
Mein Dockerfiles für jedes Projekt < /p>
 Projekt 1: < /h1>
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
USER $APP_UID
WORKDIR /app
EXPOSE 8080
EXPOSE 8081

FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["ReportService/ReportService.csproj", "ReportService/"]
RUN dotnet restore "./ReportService/ReportService.csproj"
COPY . .
WORKDIR "/src/ReportService"
RUN dotnet build "./ReportService.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./ReportService.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY ReportService/appsettings.json /app/
COPY ReportService/appsettings.Development.json /app/
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ReportService.dll"]
< /code>
 Projekt 2 < /h1>
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
USER $APP_UID
WORKDIR /app
EXPOSE 8080
EXPOSE 8081

FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["DirectoryService/DirectoryService.csproj", "DirectoryService/"]
RUN dotnet restore "./DirectoryService/DirectoryService.csproj"
COPY . .
WORKDIR "/src/DirectoryService"
RUN dotnet build "./DirectoryService.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./DirectoryService.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY DirectoryService/appsettings.json /app/
COPY DirectoryService/appsettings.Development.json /app/
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "DirectoryService.dll"]
Wie kann ich das beheben und weiter arbeiten?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post