2017-10-15 177 views
2

我想将一个asp.net核心应用程序部署到泊坞窗容器中。该应用程序是通过使用dotnet new mvc创建的。应用程序运行时一切正常,都是非docker环境。但是,在泊坞窗容器中,浏览器无法加载wwwroot文件夹中的所有静态文件。 这里是Program.cs的当Docker容器中运行asp.net核心应用程序时,UseStaticFiles不起作用

public class Program 
{ 
    public static void Main(string[] args) 
    { 
     BuildWebHost(args).Run(); 
    } 

    public static IWebHost BuildWebHost(string[] args) => 
     WebHost.CreateDefaultBuilder(args) 
      .UseStartup<Startup>() 
      .UseKestrel() 
      .UseContentRoot(Directory.GetCurrentDirectory()) 
      .UseWebRoot(Path.Combine(Directory.GetCurrentDirectory(),"wwwroot")) 
      .UseUrls("http://*:5050") 
      .Build(); 
} 

这里是Startup.cs

public class Startup 
{ 
    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.AddMvc(); 
    } 

    // 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.UseStaticFiles(); 

     app.UseMvc(routes => 
     { 
      routes.MapRoute(
       name: "default", 
       template: "{controller=Home}/{action=Index}/{id?}"); 
     }); 
    } 
} 

}

下面是

FROM microsoft/aspnetcore 
RUN mkdir -p /app 
COPY app/* /app/ 
WORKDIR /app 
CMD ["dotnet","/app/app.dll"] 
+0

什么返回'Directory.GetCurrentDirectory()'纠正?可能它映射到错误的目录 – ingvar

回答

0

我在犯了一些错误的dockerfile dockerfile。

下面的命令无法复制源目录递归

COPY app/* /app/ 

相反,COPY命令应如下支持递归

COPY app/ /app/ 
相关问题