【发布时间】:2017-10-16 10:10:03
【问题描述】:
我正在尝试将一个 asp.net 核心应用程序部署到 docker 容器中。该应用程序是使用 dotnet new mvc 创建的。当应用程序运行是非 docker 环境时,一切正常。但是,在 docker 容器中,浏览器无法加载 wwwroot 文件夹中的所有静态文件。
这是Program.cs
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?}");
});
}
}
}
这里是 dockerfile
FROM microsoft/aspnetcore
RUN mkdir -p /app
COPY app/* /app/
WORKDIR /app
CMD ["dotnet","/app/app.dll"]
【问题讨论】:
-
什么返回
Directory.GetCurrentDirectory()?可能它映射到错误的目录