[Original] Run the ASP. NET Core site and dockercore in Docker

Source: Internet
Author: User
Tags git hooks

[Original] Run the ASP. NET Core site and dockercore in Docker

1. Create a. NetCore Project

A. Create a project

Bytes ------------------------------------------------------------------------------------

Bytes ------------------------------------------------------------------------------------

B. Select the project type

Bytes ------------------------------------------------------------------------------------

Bytes ------------------------------------------------------------------------------------

C. Add a controller

Bytes ------------------------------------------------------------------------------------

Bytes -----------------------------------------------------------------------------------

Bytes ------------------------------------------------------------------------------------

Bytes -------------------------------------------------------------------------------------

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

Bytes -------------------------------------------------------------------------------------

Bytes --------------------------------------------------------------------------------------

D. Add a view

Bytes -------------------------------------------------------------------------------------

 

Bytes ---------------------------------------------------------------------------------------

1 @ {2 Layout = null; 3} 4 5 <! DOCTYPE html> 6 7 Bytes ---------------------------------------------------------------------------------------

Bytes ---------------------------------------------------------------------------------------

E. Modify the default request

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 (IHostingEnvironmen T env) 16 {17 var builder = new ConfigurationBuilder () 18. setBasePath (env. contentRootPath) 19. addJsonFile ("deleteworkflow. json ", optional: false, reloadOnChange: true) 20. addJsonFile ($ "deleettings. {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 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 loggerFa Ctory. addConsole (Configuration. getSection ("Logging"); 38 loggerFactory. addDebug (); 39 40 if (env. isDevelopment () 41 {42 app. usemediaexceptionpage (); 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

Bytes ---------------------------------------------------------------------------------------

Bytes --------------------------------------------------------------------------------------

F. Release

Bytes ---------------------------------------------------------------------------------------

Bytes ---------------------------------------------------------------------------------------

2. Prepare the CentOS Environment

A. Prepare a virtual machine.

Bytes ---------------------------------------------------------------------------------------

Bytes ----------------------------------------------------------------------------------------

B. Install docker

1 yum install dockerCent bash

Bytes ----------------------------------------------------------------------------------------

Bytes -----------------------------------------------------------------------------------------

C. Set the docker Service

1 systemctl start docker. service2 systemctl enable docker. serviceCent bash

Bytes -----------------------------------------------------------------------------------------

Bytes -----------------------------------------------------------------------------------------

3. Package site Images

A. Put the program into/root

Bytes -----------------------------------------------------------------------------------------

Bytes -----------------------------------------------------------------------------------------

Bytes ----------------------------------------------------------------------------------------

Bytes -----------------------------------------------------------------------------------------

B. Switch the command to DemoLM.

1 cd./DemoLMCent bash

Bytes -----------------------------------------------------------------------------------------

Bytes --------------------------------------------------------------------------------------

C. Create a Dockerfile

1 vim./DockerfileCent bash

Bytes --------------------------------------------------------------------------------------

Bytes ------------------------------------------------------------------------------------

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

Bytes -----------------------------------------------------------------------------------

Bytes ------------------------------------------------------------------------------------

D. Package the image

1 docker build-t lmapp: 1.0.Cent bash

Bytes ------------------------------------------------------------------------------------

 

Bytes ---------------------------------------------------------------------------------------

4. Run the image and browse the website

A. view images

1 docker imagesCent bash

Bytes ---------------------------------------------------------------------------------------

Bytes ----------------------------------------------------------------------------------------

B. Run the image

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

Bytes ----------------------------------------------------------------------------------------

Bytes ----------------------------------------------------------------------------------------

C. view the running status

1 docker logs lmweb10Cent bash

Bytes ---------------------------------------------------------------------------------------

Bytes -----------------------------------------------------------------------------------------

1 docker psCent bash

Bytes -----------------------------------------------------------------------------------------

Bytes ------------------------------------------------------------------------------------------

D. Browse the site

Bytes -------------------------------------------------------------------------------------------

Bytes ----------------------------------------------------------------------------------------

5. For more information, see the PPT sharing O (workshop _ Workshop) O Haha ~ (PS: Follow up on subsequent blogs)

A. Linux

B. NetCore

C. Docker explanation

E. Git hooks

F. Visual Studio

 

Mon

Wednesday

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.