aspnet / aspnet-docker

[Archived] ASP.NET Core Docker images for 1.x. Go to https://github.com/dotnet/dotnet-docker for 2.1 and up.
https://asp.net
719 stars 171 forks source link

Can't run docker app in visual studio on release mode by dependencies #434

Closed FerAguilarR93 closed 5 years ago

FerAguilarR93 commented 5 years ago

Describe the bug

Hello, I have a problem with visual studio 2017 and docker on release mode, I don't know what's the problem but when I run the project in debug mode all works ok, but on release mode VS can´t create docker image of my project I'm working with: 1° visual studio 2017 version 15.9.3 2° Docker Version 2.0.0.0-win81 (29211)

Steps to reproduce the issue

1° Create a solutuion with a class library with .net core 2.1 2° Create a second solution with an ASP .NET CORE WebApplication(asp .net core 2.1) with docker and https compatibility 3° Add the class library to webapp(class library is added as assembly) 4° Compile webapp(compile succesfully without errors) 5° Run WebApp in release mode (can't generate a docker image)

The output says that can't create docker image because dependency is missing, my docker file is by default I haven't modified it.

here is my output:

1>  Generating MSBuild file /src/AdvanFuelModels/obj/AdvanFuelModels.csproj.nuget.g.targets.
1>  Restore completed in 13.69 ms for /src/AdvanFuelModels/AdvanFuelModels.csproj.
1>  Restoring packages for /src/MicroserviceAdvanFuelInterfaces/MicroserviceAdvanFuelInterfaces.csproj...
1>/src/MicroserviceAdvanFuelInterfaces/MicroserviceAdvanFuelInterfaces.csproj : error NU1101: Unable to find package AdvanCoreApiBusiness. No packages exist with this id in source(s): nuget.org
1>  Generating MSBuild file /src/MicroserviceAdvanFuelInterfaces/obj/MicroserviceAdvanFuelInterfaces.csproj.nuget.g.props.
1>  Restore failed in 3.82 sec for /src/MicroserviceAdvanFuelInterfaces/MicroserviceAdvanFuelInterfaces.csproj.
1>Build FAILED.
1>
1>/src/AdvanFuelInterfacesDao/AdvanFuelInterfacesDao.csproj : error NU1101: Unable to find package AdvanCoreApiBusiness. No packages exist with this id in source(s): nuget.org [/src/MicroserviceAdvanFuelInterfaces/MicroserviceAdvanFuelInterfaces.csproj]
1>/src/AdvanFuelInterfacesBusiness/AdvanFuelInterfacesBusiness.csproj : error NU1101: Unable to find package AdvanCoreApiBusiness. No packages exist with this id in source(s): nuget.org [/src/MicroserviceAdvanFuelInterfaces/MicroserviceAdvanFuelInterfaces.csproj]
1>/src/MicroserviceAdvanFuelInterfaces/MicroserviceAdvanFuelInterfaces.csproj : error NU1101: Unable to find package AdvanCoreApiBusiness. No packages exist with this id in source(s): nuget.org
1>    0 Warning(s)
1>    3 Error(s)
1>
1>Time Elapsed 00:00:07.81
1>The command '/bin/sh -c dotnet build "MicroserviceAdvanFuelInterfaces.csproj" -c Release -o /app' returned a non-zero code: 1
1>C:\Users\USUARIO\.nuget\packages\microsoft.visualstudio.azure.containers.tools.targets\1.0.2105168\build\Container.targets(255,5): error : An error occurred while attempting to build Docker image.
1>Done building project "MicroserviceAdvanFuelInterfaces.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 3 up-to-date, 0 skipped ==========

this only occurs on release mode but it works on debug mode any idea on how to solve this?... thanks in advance.

natemcmaster commented 5 years ago

Can you please share steps to reproduce this?

FerAguilarR93 commented 5 years ago

I have added some steps to reproduce the problem if more information is needed. Please, tell me and thank you for your help.

natemcmaster commented 5 years ago

Can you share your dockerfile? My guess is that you need to update it manually to include the new project you added in step 3.

FerAguilarR93 commented 5 years ago

this is my dockerfile:

FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY ["MicroserviceAdvanFuelInterfaces/MicroserviceAdvanFuelInterfaces.csproj", "MicroserviceAdvanFuelInterfaces/"]
RUN dotnet restore "MicroserviceAdvanFuelInterfaces/MicroserviceAdvanFuelInterfaces.csproj"
COPY . .
WORKDIR "/src/MicroserviceAdvanFuelInterfaces"
RUN dotnet build "MicroserviceAdvanFuelInterfaces.csproj" -c Release -o /app

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

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "MicroserviceAdvanFuelInterfaces.dll"]
natemcmaster commented 5 years ago
  COPY ["MicroserviceAdvanFuelInterfaces/MicroserviceAdvanFuelInterfaces.csproj", "MicroserviceAdvanFuelInterfaces/"]
+ COPY ["AdvanFuelInterfacesDao/AdvanFuelInterfacesDao.csproj", "AdvanFuelInterfacesDao/"]
+ COPY ["AdvanFuelInterfacesBusiness/AdvanFuelInterfacesBusiness.csproj", "AdvanFuelInterfacesBusiness/"]
  RUN dotnet restore "MicroserviceAdvanFuelInterfaces/MicroserviceAdvanFuelInterfaces.csproj"
FerAguilarR93 commented 5 years ago

That's for the class library under the same solution but still I have the problem, I try to add my AdvanCoreApiBusiness.csproj but Docker can't find it because this is in another solution

natemcmaster commented 5 years ago

Sounds like you need to move your projects so they are in the same solution. This is a requirement to have the same projects in a single Docker build context.

It sounds to me like you're running into problems using Docker, specifically, in understanding how the Docker build context works. I'm going to close as there doesn't appear to be any issues with the ASP.NET Core, but rather, with how you have setup your projects. There isn't any actionable item here for the ASP.NET Core docker images, but feel free to continue discussion if you have more questions about how Docker works. You may also try using other forums like Stack Overflow or https://developercommunity.visualstudio.com.