Home > Net >  Docker deployment start access aspnet applications
Docker deployment start access aspnet applications

Time:11-04

 public class Program 
{
Public static void Main (string [] args)
{
Try
{
//like to solve Chinese garbled
Encoding. RegisterProvider (CodePagesEncodingProvider. Instance);

Var builder=new ServiceHostBuilder ();

Var host=builder. RegisterServices ((container)=& gt;
{

}). UseWeb ()
The Build ();

The host. The Run ();



}
The catch (Exception ex)
{
Console. WriteLine (ex. Message);
}

}

Public static IHostBuilder CreateHostBuilder (string [] args)=& gt;
Host. CreateDefaultBuilder (args)
ConfigureWebHostDefaults (webBuilder=& gt;
{
WebBuilder. UseStartup (a);
});
}


I put the original startup code UseWeb, deployed to the docker can't access, but is can access local direct start,

Docker run - name netcore - web - d - 8999 p: 80 core - web start

 public static IServiceHostBuilder UseWeb (this IServiceHostBuilder serviceHostBuilder) 
{
Var executeAss=Assembly. GetCallingAssembly ();
Var path=path. GetDirectoryName (Assembly. GetCallingAssembly (). The Location).
Var viewDll=Path.Com bine (path, executeAss GetName (). The Name + ". Views. DLL ");

The Assembly viewAsm=null;

If (the File. The Exists (viewDll))
{
ViewAsm=Assembly. LoadFrom (viewDll);

}

ServiceHostBuilder. AddHostService ((IHostBuilder hostBuilder)=& gt;
{
HostBuilder. ConfigureWebHostDefaults (webHostBuilder=& gt;
{

WebHostBuilder
ConfigureServices (services=& gt;
{
Services. AddControllersWithViews ();
Var mvcBuilder=services. AddMvc ();
If (viewAsm!=null)
{
MvcBuilder. AddApplicationPart (viewAsm);
}
MvcBuilder. AddApplicationPart (executeAss);

})
Configure ((context, app)=& gt;
{
If (context. HostingEnvironment. IsDevelopment ())
{
App. UseDeveloperExceptionPage ();
}
The else
{
App. UseExceptionHandler ("/Home/Error ");
//The default value is 30 days HSTS. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
App. UseHsts ();
}
App. UseHttpsRedirection ();
App. UseStaticFiles ();

App. UseRouting ();

App. UseAuthorization ();

App. UseEndpoints (endpoints=& gt;
{
Endpoints. MapControllerRoute (
Name: "default",
The pattern: "{controller=Home}/{action=Index}/{id? } ");
});
});

});

});



Return serviceHostBuilder;
}

CodePudding user response:

If you can't connect the database, first to see if you install the container starts, you can debug your container, look in that step

CodePudding user response:

Docker logs - since 30 m container ID
  • Related