无法使用Docker-compose构建.Net Core Docker映像

时间:2020-05-18 10:24:31

标签: docker asp.net-core docker-compose

嗨,我正在尝试使用docker-compose构建.Net核心应用程序的docker映像。下面是我的.Net核心应用程序的文件夹结构

MicroServices \ UserAccountMicroService \ UserAccountMicroService \ UserAccountMicroService 这是放置.NetCore应用程序的Dockerfile的位置。

下面是我的Dockerfile。

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["UserAccountMicroService/UserAccountMicroService/UserAccountMicroService/UserAccountMicroService.csproj", "UserAccountMicroService/"]
RUN dotnet restore "UserAccountMicroService/UserAccountMicroService.csproj"
COPY . .
WORKDIR "/src/UserAccountMicroService"
RUN dotnet build "UserAccountMicroService.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "UserAccountMicroService.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "UserAccountMicroService.dll"]

在MicroServices文件夹中,我保留了docker-compose文件。

下面是我的docker compose文件。

版本:“ 2.4”

services:
  useraccountservice:
    build:
      context: .
      dockerfile:  UserAccountMicroService/UserAccountMicroService/UserAccountMicroService/Dockerfile 
      args:
        http_proxy: "${http_proxy}" 
        https_proxy: "${https_proxy}"
        BUILD_NUMBER: "local"
      network: host # Need access to localhost for cntlm proxy
    image: useraccountmicroservice
    container_name: UserAccountMicroService 
    mem_limit: 3072m
    ports:
      - 32778:443

运行时

docker-compose up

我得到以下输出。

WARNING: The http_proxy variable is not set. Defaulting to a blank string.
WARNING: The https_proxy variable is not set. Defaulting to a blank string.
Building useraccountservice
Step 1/17 : FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
 ---> 4bee399eb313
Step 2/17 : WORKDIR /app
 ---> Using cache
 ---> 6478fff34547
Step 3/17 : EXPOSE 80
 ---> Using cache
 ---> b57cbece5b5f
Step 4/17 : EXPOSE 443
 ---> Using cache
 ---> 58eb9e8e4a2c

Step 5/17 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
 ---> a0dbfc5da130
Step 6/17 : WORKDIR /src
 ---> Using cache
 ---> 5d7295053df7
Step 7/17 : COPY ["UserAccountMicroService/UserAccountMicroService/UserAccountMicroService/UserAccountMicroService.csproj", "UserAccountMicroService/"]
 ---> Using cache
 ---> bf0798b2c68d
Step 8/17 : RUN dotnet restore "UserAccountMicroService/UserAccountMicroService.csproj"
 ---> Using cache
 ---> 1ede13152845
Step 9/17 : COPY . .
 ---> Using cache
 ---> 37af61295a72
Step 10/17 : WORKDIR "/src/UserAccountMicroService"
 ---> Using cache
 ---> 0acf075ed74a
Step 11/17 : RUN dotnet build "UserAccountMicroService.csproj" -c Release -o /app/build
 ---> Running in e6f01d1214eb
Microsoft (R) Build Engine version 16.5.0+d4cbfca49 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 32.97 ms for /src/UserAccountMicroService/UserAccountMicroService.csproj.
obj/Release/netcoreapp3.1/UserAccountMicroService.AssemblyInfo.cs(13,12): error CS0579: Duplicate 'Microsoft.Extensions.Configuration.UserSecrets.UserSecretsIdAttribute' attribute [/src/UserAccountMicroService/UserAccountMicroService.csproj]
obj/Release/netcoreapp3.1/UserAccountMicroService.AssemblyInfo.cs(14,12): error CS0579: Duplicate 'System.Reflection.AssemblyCompanyAttribute' attribute [/src/UserAccountMicroService/UserAccountMicroService.csproj]
obj/Release/netcoreapp3.1/UserAccountMicroService.AssemblyInfo.cs(15,12): error CS0579: Duplicate 'System.Reflection.AssemblyConfigurationAttribute' attribute [/src/UserAccountMicroService/UserAccountMicroService.csproj]
obj/Release/netcoreapp3.1/UserAccountMicroService.AssemblyInfo.cs(16,12): error CS0579: Duplicate 'System.Reflection.AssemblyFileVersionAttribute' attribute [/src/UserAccountMicroService/UserAccountMicroService.csproj]
obj/Release/netcoreapp3.1/UserAccountMicroService.AssemblyInfo.cs(17,12): error CS0579: Duplicate 'System.Reflection.AssemblyInformationalVersionAttribute' attribute [/src/UserAccountMicroService/UserAccountMicroService.csproj]
obj/Release/netcoreapp3.1/UserAccountMicroService.AssemblyInfo.cs(18,12): error CS0579: Duplicate 'System.Reflection.AssemblyProductAttribute' attribute [/src/UserAccountMicroService/UserAccountMicroService.csproj]
obj/Release/netcoreapp3.1/UserAccountMicroService.AssemblyInfo.cs(19,12): error CS0579: Duplicate 'System.Reflection.AssemblyTitleAttribute' attribute [/src/UserAccountMicroService/UserAccountMicroService.csproj]
obj/Release/netcoreapp3.1/UserAccountMicroService.AssemblyInfo.cs(20,12): error CS0579: Duplicate 'System.Reflection.AssemblyVersionAttribute' attribute [/src/UserAccountMicroService/UserAccountMicroService.csproj]

Build FAILED.

obj/Release/netcoreapp3.1/UserAccountMicroService.AssemblyInfo.cs(13,12): error CS0579: Duplicate 'Microsoft.Extensions.Configuration.UserSecrets.UserSecretsIdAttribute' attribute [/src/UserAccountMicroService/UserAccountMicroService.csproj]
obj/Release/netcoreapp3.1/UserAccountMicroService.AssemblyInfo.cs(14,12): error CS0579: Duplicate 'System.Reflection.AssemblyCompanyAttribute' attribute [/src/UserAccountMicroService/UserAccountMicroService.csproj]
obj/Release/netcoreapp3.1/UserAccountMicroService.AssemblyInfo.cs(15,12): error CS0579: Duplicate 'System.Reflection.AssemblyConfigurationAttribute' attribute [/src/UserAccountMicroService/UserAccountMicroService.csproj]
obj/Release/netcoreapp3.1/UserAccountMicroService.AssemblyInfo.cs(16,12): error CS0579: Duplicate 'System.Reflection.AssemblyFileVersionAttribute' attribute [/src/UserAccountMicroService/UserAccountMicroService.csproj]
obj/Release/netcoreapp3.1/UserAccountMicroService.AssemblyInfo.cs(17,12): error CS0579: Duplicate 'System.Reflection.AssemblyInformationalVersionAttribute' attribute [/src/UserAccountMicroService/UserAccountMicroService.csproj]
obj/Release/netcoreapp3.1/UserAccountMicroService.AssemblyInfo.cs(18,12): error CS0579: Duplicate 'System.Reflection.AssemblyProductAttribute' attribute [/src/UserAccountMicroService/UserAccountMicroService.csproj]
obj/Release/netcoreapp3.1/UserAccountMicroService.AssemblyInfo.cs(19,12): error CS0579: Duplicate 'System.Reflection.AssemblyTitleAttribute' attribute [/src/UserAccountMicroService/UserAccountMicroService.csproj]
obj/Release/netcoreapp3.1/UserAccountMicroService.AssemblyInfo.cs(20,12): error CS0579: Duplicate 'System.Reflection.AssemblyVersionAttribute' attribute [/src/UserAccountMicroService/UserAccountMicroService.csproj]
    0 Warning(s)
    8 Error(s)

Time Elapsed 00:00:01.78
ERROR: Service 'useraccountservice' failed to build: The command '/bin/sh -c dotnet build "UserAccountMicroService.csproj" -c Release -o /app/build' returned a non-zero code: 1

我只是想弄清楚dockerfile配置中缺少的内容。有人可以帮我弄清楚吗?任何帮助将不胜感激。谢谢

0 个答案:

没有答案