[英]Asp .NET MVC Core application not running in Windows Docker container
I am trying to deploy an asp.net core mvc application in the docker container, when i run the application i get the following error in the docker logs我正在尝试在 docker 容器中部署一个 asp.net core mvc 应用程序,当我运行该应用程序时,我在 docker 日志中收到以下错误
fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware 1 An unhandled exception has occurred while executing the request.失败:Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware 1执行请求时发生未处理的异常。 System.ArgumentNullException: Value cannot be null. System.ArgumentNullException:值不能为空。 Parameter name: connectionString参数名称:connectionString
I have mentioned the connection string in my appsettings.json file but still it does not fetch it correctly.我在 appsettings.json 文件中提到了连接字符串,但它仍然没有正确获取它。
appsettings.json appsettings.json
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnection": "<<< AZURE-SQL CONNECTION STRING >>>"
}
}
Startup.cs启动文件
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddMvc().AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());
services.AddScoped<IBusinessLogic, BusinessLogic>();
services.AddScoped<IDataRepository, DataRepository>();
var connection = Configuration.GetConnectionString("DefaultConnection");
services.AddDbContext<DataContext>(options => options.UseSqlServer(connection));
services.AddScoped<DataContext>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Mvc}/{action=Design}/{id?}");
});
}
Published folder已发布文件夹
Dockerfile文件
FROM microsoft/dotnet:2.1-aspnetcore-runtime
EXPOSE 80
COPY /publish/ /app
ENTRYPOINT ["dotnet", "MVC_Module_Designer.dll"]
Docker commands used to publish用于发布的 Docker 命令
docker build -t webapp .
docker run -p 8080:80 webapp
Am i missing out anything for deployment of asp.net mvc core application in docker container ?.我是否遗漏了在 docker 容器中部署 asp.net mvc 核心应用程序的任何内容?
I have found the issue that i have made, its in the Docker file, after copying the published folder to app directory, did not change it to that.我发现了我所做的问题,它在 Docker 文件中,在将发布的文件夹复制到 app 目录后,并没有将其更改为那个。 Hence it resulted in that error.因此它导致了那个错误。
Correct docker file正确的 docker 文件
FROM microsoft/dotnet:2.1-aspnetcore-runtime
EXPOSE 80
WORKDIR /app
COPY /publish .
ENTRYPOINT ["dotnet", "MVC_Module_Designer.dll"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.