博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【原创】 Docker 中 运行 ASP.NET Core 站点
阅读量:5242 次
发布时间:2019-06-14

本文共 7628 字,大约阅读时间需要 25 分钟。

索引:

一. 建立 .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; 6  7 namespace DemoLM.Controllers 8 { 9     public class DockerTestController : Controller10     {11         public IActionResult DockerIndex()12         {13             return View();14         }15     }16 }
DockerTestController

-------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------

        d.添加视图

-------------------------------------------------------------------------------------

 

---------------------------------------------------------------------------------------

1 @{ 2     Layout = null; 3 } 4  5  6  7  8  9     
10 DockerIndex11 12 13

这是Docker中的Asp.net Core APP !

14 15
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;10 11 namespace DemoLM12 {13     public class Startup14     {15         public Startup(IHostingEnvironment env)16         {17             var builder = new ConfigurationBuilder()18                 .SetBasePath(env.ContentRootPath)19                 .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)20                 .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)21                 .AddEnvironmentVariables();22             Configuration = builder.Build();23         }24 25         public IConfigurationRoot Configuration { get; }26 27         // This method gets called by the runtime. Use this method to add services to the container.28         public void ConfigureServices(IServiceCollection services)29         {30             // Add framework services.31             services.AddMvc();32         }33 34         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.35         public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)36         {37             loggerFactory.AddConsole(Configuration.GetSection("Logging"));38             loggerFactory.AddDebug();39 40             if (env.IsDevelopment())41             {42                 app.UseDeveloperExceptionPage();43                 app.UseBrowserLink();44             }45             else46             {47                 app.UseExceptionHandler("/Home/Error");48             }49 50             app.UseStaticFiles();51 52             app.UseMvc(routes =>53             {54                 routes.MapRoute(55                     name: "default",56                     template: "{controller=DockerTest}/{action=DockerIndex}/{id?}");57             });58         }59     }60 }
Startup

---------------------------------------------------------------------------------------

 --------------------------------------------------------------------------------------

      f.发布

---------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------

二. 准备 CentOS 环境

       a.准备虚拟机

---------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------

       b.安装 docker

1 yum install docker
cent bash

----------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------

       c.设置docker 服务

1 systemctl start docker.service2 systemctl enable docker.service
cent bash

-----------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------

三. 打包 站点镜像

       a.将程序放入 /root

-----------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------

       b.命令切换至 DemoLM

1 cd ./DemoLM
cent bash

-----------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------

      c.创建 Dockerfile

1 vim ./Dockerfile
cent bash

--------------------------------------------------------------------------------------

------------------------------------------------------------------------------------

1 FROM docker.io/microsoft/aspnetcore2 COPY ./bin/Release/PublishOutput ./publish3 WORKDIR /publish4 EXPOSE 805 CMD ["dotnet","DemoLM.dll"]
image bash

-----------------------------------------------------------------------------------

------------------------------------------------------------------------------------

      d.打包镜像

1 docker build -t lmapp:1.0 .
cent bash

------------------------------------------------------------------------------------

 

---------------------------------------------------------------------------------------

四. 运行镜像 并浏览网站

        a.查看镜像

1 docker images
cent bash

---------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------

      b.运行镜像

1 docker run -d -t --name lmweb10 -p 8800:80 lmapp:1.0
cent bash

----------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------

       c.查看运行状态

1 docker logs lmweb10
cent bash

---------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------

1 docker ps
cent bash

-----------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------

      d.浏览站点

-------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------

五. 详细知识点讲解,请看PPT 分享 O(∩_∩)O哈哈~  ( PS:请关注后续博客 )

       a. Linux 讲解

       b. .NetCore 讲解

       c. Docker 讲解

       e. Git hooks 讲解

       f. Visual Studio 讲解

 

                                         蒙

                                    2017-07-05  14:28  周三

 

转载于:https://www.cnblogs.com/Meng-NET/p/7121118.html

你可能感兴趣的文章
多线程实现资源共享的问题学习与总结
查看>>
Learning-Python【26】:反射及内置方法
查看>>
torch教程[1]用numpy实现三层全连接神经网络
查看>>
java实现哈弗曼树
查看>>
转:Web 测试的创作与调试技术
查看>>
python学习笔记3-列表
查看>>
程序的静态链接,动态链接和装载 (补充)
查看>>
关于本博客说明
查看>>
线程androidAndroid ConditionVariable的用法
查看>>
FTTB FTTC FTTH FTTO FSA
查看>>
OpenAI Gym
查看>>
stap-prep 需要安装那些内核符号
查看>>
网易杭研后台技术中心的博客 -MYSQL :OOM
查看>>
第二章 数据通信的基础知识 计算机网络笔记 学堂在线 2.1 数据传输系统 2.2 信号...
查看>>
如何解决click事件的重复触发问题
查看>>
2016寒假自学笔记
查看>>
VC++2012编程演练数据结构《21》二叉排序树
查看>>
Easyui NumberBox格式化展示
查看>>
转载:ASP.NET Core 在 JSON 文件中配置依赖注入
查看>>
socket初识
查看>>