简体   繁体   English

Asp .NET MVC Core 应用程序未在 Windows Docker 容器中运行

[英]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.

相关问题 在 Docker 中运行 ASP.NET Core 应用程序时丢失文件:如何在容器运行时显示文件? - Missing files when running ASP.NET Core application in Docker: How to display files when the container is running? 无法从docker windows容器中的asp.net核心应用程序连接到主机数据库 - Not able to connect to host database from asp.net core application which is in docker windows container 如何从在容器中运行的 ASP.NET 核心应用程序连接到具有集成安全性的 Windows 服务器上的 SQL 服务器 - How to connect from ASP.NET Core application running in a container to SQL Server on Windows Server with Integrated Security Asp.NET 核心 WebAPI 未在 docker 容器中运行 - Asp.NET Core WebAPI not running in docker container 在具有 memory 限制的 Docker 容器中运行 .NET 核心应用程序 - Running .NET Core application in Docker container with memory limit 如何在 docker 容器中运行 asp.net 核心应用程序? - How to run an asp.net core application in docker container? 使用 docker 容器上的数据库部署 ASP.NET Core 应用程序 - Deploying an ASP.NET Core Application with a database that is on a docker container .Net Core 控制台应用程序未在 Docker 容器中运行 - .Net Core Console App not running in Docker container docker容器的ASP.NET MVC问题 - ASP.NET MVC Issue with docker container 在没有 .NET Core SDK 的情况下将 ASP.NET Core MVC 作为控制台应用程序项目运行 - Running ASP.NET Core MVC as a Console Application Project without .NET Core SDK
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM