MarcinAWK
MarcinAWK

Reputation: 63

Build Docker with Visual Studio with ASPNETCORE_ENVIRONMENT Production

I don't know how to set my docker image as production image. I have tried:

Dockerfile

ENV ASPNETCORE_ENVIRONMENT Production

Dockerfile

ENTRYPOINT["dotnet", "Isofy-Api.dll",  "--environment="Production"]

launchSettings.json

"Docker": {
  "commandName": "Docker",
  "launchBrowser": true,
  "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
  "publishAllPorts": true,
  "useSSL": false,
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Production"
  }
}

And still docker is compiled as a Development. How to fix that?

Here is my dockerfile:

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
ENV ASPNETCORE_ENVIRONMENT Production

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["Reservation2/Reservation2.csproj", "Reservation2/"]
RUN dotnet restore "Reservation2/Reservation2.csproj"
COPY . .
WORKDIR "/src/Reservation2"
ENV ASPNETCORE_ENVIRONMENT Production
RUN dotnet build "Reservation2.csproj" -c Release -o /app/build

FROM build AS publish
ENV ASPNETCORE_ENVIRONMENT Production
RUN dotnet publish "Reservation2.csproj" -c Release -o /app/publish

ENV ASPNETCORE_ENVIRONMENT Production

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

Upvotes: 0

Views: 321

Answers (1)

Hans Kilian
Hans Kilian

Reputation: 25569

The default error text in Razor apps (which is what I think you're getting) is

The Development environment shouldn't be enabled for deployed applications.
    It can result in displaying sensitive information from exceptions to end users.
    For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development
    and restarting the app.

You might think that that means that your app is running in development mode. It doesn't. It means that you're not running in development mode and that's why you're not getting detailed error information. It then gives you instructions on how to run the app in development mode, so you can get the detailed error information.

If you want to change the text above, it's in Pages/Error.cshtml.

Upvotes: 1

Related Questions