Quick deploy netcore project to docker


Install qick deploy tool

Vs plugin named AntDeploy
(support vs2015,vs2017)

Docker只能针对linux服务器 centos7+ 和 ubuntu16.04+

docker发布是基于ssh实现的,所以不需要在linux服务器上安装agent
必须要服务器上安装了docker
我这里用centos 7 vmware虚拟机做测试演示

1.为了发布速度快 需要在服务器上提前安装好netcore runtime基础镜像

安装基础镜像的命令为:
docker pull microsoft/dotnet:{sdkVersion}-aspnetcore-runtime
我这里用的netcore的sdk版本是2.1
所以如下图:

2.创建一个netcore项目

2.在工程上点击右键然后选择 AntDeploy 发布

3配置AntDeploy

3.1添加一个环境 名字叫 测试

3.2在 测试环境里面添加 Linux服务器 这里我做测试就添加就是我的centos7 虚拟机

Host填入格式 IP:Pory (如果Port是默认的端口可以只填IP不填port)
UserName填入 root
Pwd 填入 root的对应的密码

注意:点击【Connect Test】按钮进行确认服务器可以成功链接,否则会发布失败

3.3进入 Docker Tab界面

注意:如果你的工程里面没有DockerFile那么就会用默认的DockerFile
如果你工程有DockerFile就会按照它去执行

在这个测试demo里面我工程没有DockerFile
所以我在Port里面填写了5002 代表是容器外露并使用5002端口
ASPNETCORE_ENVIROMENT 我填空 代表采用默认的 appsettings.json配置

点击 【Deploy】按钮进行发布
如下图所示:

确认服务器无误 点击 【是】开始执行一键部署
发布成功如下图:

可以查看发布详细LOG
`
18:01:17|INFO|The Porject ENTRYPOINT name:TestNetcoreDocker.dll

18:01:17|INFO|Start publish

18:01:17|INFO|用于 .NET Core 的 Microsoft (R) 生成引擎版本 15.9.20+g88f5fadfbe

18:01:17|INFO|版权所有(C) Microsoft Corporation。保留所有权利。

18:01:18|INFO| C:\Users\Administrator\source\repos\TestNetcoreDocker\TestNetcoreDocker\TestNetcoreDocker.csproj 的还原在 68.74 ms 内完成。

18:01:19|INFO| TestNetcoreDocker -> C:\Users\Administrator\source\repos\TestNetcoreDocker\TestNetcoreDocker\bin\Release\netcoreapp2.1\TestNetcoreDocker.dll

18:01:19|INFO| TestNetcoreDocker -> C:\Users\Administrator\source\repos\TestNetcoreDocker\TestNetcoreDocker\bin\Release\netcoreapp2.1\TestNetcoreDocker.Views.dll

18:01:19|INFO| TestNetcoreDocker -> C:\Users\Administrator\source\repos\TestNetcoreDocker\TestNetcoreDocker\bin\Release\netcoreapp2.1\publish\

18:01:19|INFO|publish success, ==> file://C:\Users\Administrator\source\repos\TestNetcoreDocker\TestNetcoreDocker\bin\Release\netcoreapp2.1\publish#link9
18:01:19|INFO|Start package

18:01:19|INFO|package success

18:01:19|INFO|Deploy Start

18:01:19|INFO|【Server】ssh Connecting 192.168.11.129...

18:01:20|INFO|【Server】ssh connect success:192.168.11.129

18:01:20|INFO|【Server】Changed directory to publisher/testnetcoredocker/

18:01:20|INFO|【Server】uploaded 1 %

18:01:20|INFO|【Server】uploaded 2 %

18:01:20|INFO|【Server】uploaded 3 %

18:01:20|INFO|【Server】uploaded 4 %

18:01:20|INFO|【Server】uploaded 6 %

18:01:20|INFO|【Server】uploaded 7 %

18:01:20|INFO|【Server】uploaded 8 %

18:01:20|INFO|【Server】uploaded 9 %

18:01:20|INFO|【Server】uploaded 10 %

18:01:20|INFO|【Server】uploaded 20 %

18:01:20|INFO|【Server】uploaded 30 %

18:01:20|INFO|【Server】uploaded 40 %

18:01:20|INFO|【Server】uploaded 50 %

18:01:20|INFO|【Server】uploaded 60 %

18:01:20|INFO|【Server】unzip -q publisher/testnetcoredocker/publish.zip

18:01:20|INFO|【Server】uploaded 70 %

18:01:20|INFO|【Server】uploaded 80 %

18:01:20|INFO|【Server】uploaded 90 %

18:01:20|INFO|【Server】uploaded 100 %

18:01:20|INFO|【Server】unzip success: publisher/testnetcoredocker/publish/

18:01:20|INFO|【Server】create docker file: publisher/testnetcoredocker/publish/Dockerfile

18:01:20|INFO|【Server】FROM microsoft/dotnet:2.1-aspnetcore-runtime

18:01:20|INFO|【Server】COPY . /publish

18:01:20|INFO|【Server】WORKDIR /publish

18:01:20|INFO|【Server】ENV ASPNETCORE_URLS=http://:5002

18:01:20|INFO|【Server】EXPOSE 5002

18:01:20|INFO|【Server】ENTRYPOINT ["dotnet", "TestNetcoreDocker.dll"]

18:01:20|INFO|【Server】create docker file success: publisher/testnetcoredocker/publish/Dockerfile

18:01:20|INFO|【Server】sudo docker build --no-cache --rm -t testnetcoredocker -f publisher/testnetcoredocker/publish/Dockerfile publisher/testnetcoredocker/publish/

18:01:20|INFO|【Server】Sending build context to Docker daemon 2.762MB

18:01:20|INFO|【Server】Step 1/6 : FROM microsoft/dotnet:2.1-aspnetcore-runtime

18:01:20|INFO|【Server】 ---> c14bf44dc939

18:01:20|INFO|【Server】Step 2/6 : COPY . /publish

18:01:21|INFO|【Server】 ---> 13b701b957a2

18:01:21|INFO|【Server】Step 3/6 : WORKDIR /publish

18:01:21|INFO|【Server】 ---> Running in 31f5835f55a3

18:01:21|INFO|【Server】Removing intermediate container 31f5835f55a3

18:01:21|INFO|【Server】 ---> 2befa09430fb

18:01:21|INFO|【Server】Step 4/6 : ENV ASPNETCORE_URLS=http://
:5002

18:01:21|INFO|【Server】 ---> Running in ea3aacc53d5d

18:01:21|INFO|【Server】Removing intermediate container ea3aacc53d5d

18:01:21|INFO|【Server】 ---> aea1419b8028

18:01:21|INFO|【Server】Step 5/6 : EXPOSE 5002

18:01:21|INFO|【Server】 ---> Running in f31536a15815

18:01:21|INFO|【Server】Removing intermediate container f31536a15815

18:01:21|INFO|【Server】 ---> cb3532775261

18:01:21|INFO|【Server】Step 6/6 : ENTRYPOINT ["dotnet", "TestNetcoreDocker.dll"]

18:01:21|INFO|【Server】 ---> Running in ea1bcfd23cc1

18:01:21|INFO|【Server】Removing intermediate container ea1bcfd23cc1

18:01:21|INFO|【Server】 ---> f597ea70abad

18:01:21|INFO|【Server】Successfully built f597ea70abad

18:01:21|INFO|【Server】Successfully tagged testnetcoredocker:latest

18:01:26|INFO|【Server】sudo docker run --name d_testnetcoredocker -d -p 5002:5002 testnetcoredocker:latest

18:01:26|INFO|【Server】c741f3e372273cb97a4c0a0fe1693530f1378890f7b6b7082116994541a558c2

18:01:27|INFO|publish Host: 192.168.11.129 End

18:01:27|INFO|Deploy End

`

5 检测发布docker后网站是否打开成功