Windows10应用Docker部署DoNet Core

Win10和Mac稳定版的Docker发布了,之前看了下徐磊老师的几篇Docker4Dotnet的文章http://devopshub.cn/2016/07/08/docker4dotnet-1-overview-and-helloworld/,但一直没动手。。懒癌晚期了

准备个DotNet Core的Web应用程序,测试一下,并做点小修改

就为了运行的时候验证下当前宿主的环境,没别的意思

顺便可以指定下程序入口,启动时通过命令行指定个监听端口:

               IConfiguration config  = new ConfigurationBuilder()
              .AddCommandLine(args)
                      .Build();
			
            var host = new WebHostBuilder()
			   .UseConfiguration(config)
                .UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory()) 
                .UseStartup<Startup>()
                .Build();

然后简单还原下引用,再发布一下做个测试

运行一下,证明代码是可以正常跑的。而且是在我的Machine:DESKTOP-078UA43 下运行的

 测试下Docker

安装完docker后先拉取下dotnet core的镜像 docker pull microsoft/dotnet:latest

然后可以在项目根目录下穿件个Dockerfile,填充下要打包的信息:

FROM microsoft/dotnet:latest
# Set the Working Directory
WORKDIR ./app 
# Configure the listening port to 80 
EXPOSE 5006 
# Copy the app
COPY /bin/Debug/netcoreapp1.0/publish/ /app/  
# Start the app
ENTRYPOINT dotnet DotNetCoreSample.dll --server.urls  http://*:5006 

然后就可打包运行了(docker run -d -p 5008:5004 coresample 可以注册为后台进程)

访问下http://localhost:5008/Home/About 可以看到运行环境已经在容器里了

原文地址:https://www.cnblogs.com/ylsforever/p/5736227.html