我正在尝试让我的 asp.net 核心应用程序使用 ASPNETCORE_URLS 来设置启动 URL。它没有按预期工作。
我已经尝试了我在网上找到的所有东西,但我一直被卡住。该应用程序在没有环境变量的情况下工作,并在 docker 容器中正常运行。但是在启用环境变量时不起作用。
期望结果:0.0.0.0:5000 结果:本地主机:5000
启动:
public Startup(IConfiguration configuration, IWebHostEnvironment env)
{
Configuration = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env.EnvironmentName}.json")
.AddEnvironmentVariables()
.Build();
}
Run Code Online (Sandbox Code Playgroud)
dockerfile 中的环境变量:
ENV ASPNETCORE_URLS=http://+:5000
Run Code Online (Sandbox Code Playgroud)
码头工人文件:
#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 …Run Code Online (Sandbox Code Playgroud)