docker-netcore-httpserver学习笔记

准备环境:docker-netcore-firstapp学习笔记

最终效果
启动服务

# dotnet run 
Hosting environment: Production
Content root path: /home/hwapp/bin/Debug/netcoreapp2.0/
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.

客户端访问

# docker exec -it mad_noether curl http://localhost:5000
hello world!

#docker exec -it mad_noether curl http://localhost:5000/will/any/url/work?
hello world!

编辑Program.cs,Startup.cs,hwapp.csproj
1.cat Program.cs

using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;

namespace hwapp
{
    class Program
    {
        static void Main(string[] args)
        {
        var config = new ConfigurationBuilder().AddCommandLine(args).Build();
        var host = new WebHostBuilder().UseKestrel().UseStartup<Startup>().UseConfiguration(config).Build();
        host.Run();
        }
    }
}

2.cat Startup.cs

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Http;

namespace hwapp{
    public class Startup{
        public Startup(IHostingEnvironment env){
        }

        public void Configure(IApplicationBuilder app,IHostingEnvironment env,ILoggerFactory loggerFactory){
            app.Run(async (context) => {
                    await context.Response.WriteAsync("hello world!");
                    });
        }
    }
}

3.cat hwapp.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0"/>
    <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.0.0"/>
    <PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0"/>
    <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.0"/>
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0"/>
    <PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="2.0.0"/>
</ItemGroup>
</Project>

参考资料:
《building microservice with asp.net core》

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值