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"]
什麼返回'Directory.GetCurrentDirectory()'糾正?可能它映射到錯誤的目錄 – ingvar