I am trying to deploy an asp.net core application into the docker container. The application is created by using dotnet new mvc .Everything goes fine when the application is running is non docker environment. However, in the docker container, Browser unable load all of static files in the wwwroot folder.
Here is the 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();
}
Here is the 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?}");
});
}
}
}
Here is the dockerfile
FROM microsoft/aspnetcore
RUN mkdir -p /app
COPY app/* /app/
WORKDIR /app
CMD ["dotnet","/app/app.dll"]
I have made some mistakes in the dockerfile.
The command below unable to copy the source directory recursively
COPY app/* /app/
Instead,the COPY command should be corrected as follows to support recursion
COPY app/ /app/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With