项目结构
可以忽略中间三个Console项目
ApiCenter 是一个WebAPI项目,引用了NLog.MQ项目
ApiCenter使用5001端口
public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .UseKestrel(options=>options.Listen(IPAddress.Any,5001)) .ConfigureLogging(logging => { logging.ClearProviders(); logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); }) .UseNLog() .Build();
一个简单的ValuesController
// GET api/values [HttpGet] public IEnumerable<string> Get() { //string sql = GetViewSQL("viewbiz", 1, 1, "*", null, null); return new string[] { "value1", "value2" }; }
将项目文件夹发送到CentOS(10.15.4.156)中
新建一个Dockerfile,这里已经有了
编辑内容
FROM microsoft/dotnet WORKDIR /app # copy everything else and build COPY . ./ RUN dotnet restore RUN cd ApiCenter RUN dotnet publish -c Release -o out EXPOSE 5001 ENTRYPOINT ["dotnet", "ApiCenter/out/ApiCenter.dll"]
或者使用下面的内容
FROM microsoft/dotnet WORKDIR /app # copy everything else and build COPY . ./ RUN cd ApiCenter RUN dotnet restore RUN dotnet publish -c Release -o out EXPOSE 5001 ENTRYPOINT ["dotnet", "ApiCenter/out/ApiCenter.dll"]
打包镜像
docker build -t apicenter:1.0 .
可以看到打包过程
成功后查看镜像
运行镜像
docker run -d -p 5001:5001 apicenter:1.0
查看容器状态
打开浏览器访问即可