- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在docker容器中本地运行.Net Core 3.1 Web API套件。如果我在docker run命令(docker run -e ....)中输入环境变量,一切都会正常进行。但是,当我尝试通过--env-file(作为一个文件,因为会有很多)将它们传递时,它的行为很奇怪。当我在控制台日志中记录从文件中提取的变量时,它可以正常工作。但是当我使用USE变量时,它的作用是,如果变量不存在/抛出错误。这个例子碰巧被转换为int,但是我看到字符串也有同样的问题。我可以注销它们,但是当我去使用它们或操纵它们时,就像它们不存在一样。有人看过这样的东西吗?
C#
var testPort = Environment.GetEnvironmentVariable("TestPort");
Console.WriteLine("Testing Port: " + testPort);
var testPortInt = Convert.ToInt32(testPort);
TestPort="1234"
docker build --no-cache -t telematics-web-api -f Dockerfile .
docker run --name telematics-web-api -p 8080:80 --env-file dockerlocal.env telematics-web-api
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /build
COPY . .
RUN dotnet restore && dotnet publish -c Release -o /app
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS final
WORKDIR app
COPY --from=build /app .
EXPOSE 443
EXPOSE 80
ENTRYPOINT ["dotnet", "Telematics.Web.API.dll"]
Testing Port: "1234"
Unhandled exception. System.FormatException: Input string was not in a correct format.
at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
at System.Number.ParseInt32(ReadOnlySpan`1 value, NumberStyles styles, NumberFormatInfo info)
at System.Convert.ToInt32(String value)
at Fluid.Web.API.Startup.ConfigureServices(IServiceCollection services) in /build/Telematics.Web.API/Startup.cs:line 94
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.<Invoke>g__Startup|0(IServiceCollection serviceCollection)
at Microsoft.AspNetCore.Hosting.StartupLoader.ConfigureServicesDelegateBuilder`1.<>c__DisplayClass15_0.<BuildStartupServicesFilterPipeline>g__RunPipeline|0(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.<Build>b__0(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.StartupLoader.ConfigureServicesDelegateBuilder`1.<>c__DisplayClass14_0.<ConfigureServices>g__ConfigureServicesWithContainerConfiguration|0(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.WebHost.EnsureApplicationServices()
at Microsoft.AspNetCore.Hosting.WebHost.Initialize()
at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
at Fluid.Web.API.Program.BuildWebHost(String[] args) in /build/Telematics.Web.API/Program.cs:line 24
at Fluid.Web.API.Program.Main(String[] args) in /build/Telematics.Web.API/Program.cs:line 21
var url = Environment.GetEnvironmentVariable("AuthUrl");
Console.WriteLine(url);
HttpRequestMessage request = new
HttpRequestMessage(HttpMethod.Post, url);
request.Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body));
request.Content.Headers.Remove("Content-Type");
request.Content.Headers.Add("Content-Type", "application/vnd.api+json");
request.Content.Headers.Add("version", "1.6");
var resp = client.SendAsync(request).GetAwaiter().GetResult();
AuthUrl="https://..............."
info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[3]
Route matched with {action = "Login", controller = "Account"}. Executing controller action with signature Microsoft.AspNetCore.Mvc.IActionResult Login(System.String, System.String) on controller Fluid.Web.API.Controllers.AccountController (Telematics.Web.API).
"https://URLFROMDOCKERCONFIGFILE"
info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[2]
Executed action Fluid.Web.API.Controllers.AccountController.Login (Telematics.Web.API) in 86.2836ms
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
Executed endpoint 'Fluid.Web.API.Controllers.AccountController.Login (Telematics.Web.API)'
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HLVFFOERK3K8", Request id "0HLVFFOERK3K8:00000004": An unhandled exception was thrown by the application.
System.InvalidOperationException: An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set.
at System.Net.Http.HttpClient.PrepareRequestMessage(HttpRequestMessage request)
at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request)
at Fluid.Web.API.Controllers.AccountController.Login(String userName, String password) in /build/Telematics.Web.API/Controllers/AccountController.cs:line 76
最佳答案
更改dockerlocal.env
的文件内容
TestPort="1234"
AuthUrl="https://..............."
TestPort=1234
AuthUrl=https://...............
关于c# - Docker容器中的.Net Core 3.1应用程序环境变量不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61600385/
今天有小伙伴给我留言问到,try{...}catch(){...}是什么意思?它用来干什么? 简单的说 他们是用来捕获异常的 下面我们通过一个例子来详细讲解下
我正在努力提高网站的可访问性,但我不知道如何在页脚中标记社交媒体链接列表。这些链接指向我在 facecook、twitter 等上的帐户。我不想用 role="navigation" 标记这些链接,因
说现在是 6 点,我有一个 Timer 并在 10 点安排了一个 TimerTask。之后,System DateTime 被其他服务(例如 ntp)调整为 9 点钟。我仍然希望我的 TimerTas
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我就废话不多说了,大家还是直接看代码吧~ ? 1
Maven系列1 1.什么是Maven? Maven是一个项目管理工具,它包含了一个对象模型。一组标准集合,一个依赖管理系统。和用来运行定义在生命周期阶段中插件目标和逻辑。 核心功能 Mav
我是一名优秀的程序员,十分优秀!