I'm trying to have my asp.net core app use ASPNETCORE_URLS to set the launch URL. It is not working as expected.
I have tried everything I found online, but I keep getting stuck. The app works without the environmental variables and runs in a docker container fine. But wont work when enabling environmental variables.
Desired result: 0.0.0.0:5000 Result : localhost:5000
Startup:
public Startup(IConfiguration configuration, IWebHostEnvironment env)
{
Configuration = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env.EnvironmentName}.json")
.AddEnvironmentVariables()
.Build();
}
Env variable in dockerfile:
ENV ASPNETCORE_URLS=http://+:5000
Docker File:
#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 5000
ENV ASPNETCORE_URLS=http://+:5000
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["Platform/Platform.API/Platform.API.csproj", "Platform.API/"]
COPY ["Platform/Platform.Domain/Platform.Domain.csproj", "Platform.Domain/"]
COPY ["Platform/Platform.DataAccess/Platform.DataAccess.csproj", "Platform.DataAccess/"]
RUN dotnet restore "Platform.API/Platform.API.csproj"
COPY ./Platform .
WORKDIR "/src/Platform.API"
RUN dotnet build "Platform.API.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Platform.API.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Platform.API.dll"]
The environmental variable is detected by the application, it just wont be used for some reason.
Thanks in advance!