一. 建立 .NetCore 项目
a.新建项目
------------------------------------------------------------------------------------
------------------------------------------------------------------------------------
b.选择项目类型
------------------------------------------------------------------------------------
------------------------------------------------------------------------------------
c.添加控制器
------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Threading.Tasks; 5 using Microsoft.AspNetCore.Mvc; DemoLM.Controllers 8 { DockerTestController : Controller 10 { 11 public IActionResult DockerIndex() 12 { 13 return View(); 14 } 15 } 16 }
DockerTestController-------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
d.添加视图
-------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
1 @{ 2 Layout = null; 3 } DockerIndex这是Docker中的Asp.net Core APP !
DockerIndex---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
e.修改默认请求
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Threading.Tasks; 5 using Microsoft.AspNetCore.Builder; 6 using Microsoft.AspNetCore.Hosting; 7 using Microsoft.Extensions.Configuration; 8 using Microsoft.Extensions.DependencyInjection; 9 using Microsoft.Extensions.Logging; DemoLM 12 { Startup 14 { 15 public Startup(IHostingEnvironment env) 16 { 17 var builder = new ConfigurationBuilder() 18 .SetBasePath(env.ContentRootPath) , optional: false, reloadOnChange: true) , optional: true) 21 .AddEnvironmentVariables(); 22 Configuration = builder.Build(); 23 } IConfigurationRoot Configuration { get; } ConfigureServices(IServiceCollection services) 29 { services.AddMvc(); 32 } Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 36 { )); 38 loggerFactory.AddDebug(); (env.IsDevelopment()) 41 { 42 app.UseDeveloperExceptionPage(); 43 app.UseBrowserLink(); 44 } { ); 48 } 49 50 app.UseStaticFiles(); 51 52 app.UseMvc(routes => 53 { 54 routes.MapRoute( , ); 57 }); 58 } 59 } 60 }
Startup---------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
f.发布
---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
二. 准备 CentOS 环境
a.准备虚拟机
---------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------
b.安装 docker