DotNet core SDK
首先在 Server 上準備編譯環境
Dockerfile
#2.2 3.0 3.1
FROM mcr.microsoft.com/dotnet/core/sdk:3.1
RUN mkdir /web
WORKDIR /web
build docker image shell script
docker build -t dotnetcoresdk:3.1 .
start docker container shell script
docker run -it -d \
--name dotnet-core-sdk-3.1 \
-v /opt/web:/web \
dotnetcoresdk:3.1
Jenkins
Execute shell script on remote hosting using ssh
#切換至專案目錄
cd /opt/web/project/path
#取得最新版本
git pull
#切換至專案目錄 && 刷新 Dotnet Library
docker exec -i dotnet-core-sdk-3.1 bash -c "cd project/path && dotnet restore"
#切換至專案目錄 && 刪除上一次編譯的檔案 && 編譯
docker exec -i dotnet-core-sdk-3.1 bash -c "cd project/path && rm -rf bin/Release && dotnet publish -c Release"
#docker-compose.yml 參 DotNet core Runtime Section
#!--rmi all 將原本執行的容器關閉並移除Image
docker-compose down --rmi all
#將新版程式包入 Image 並開始容器
docker-compose up -d
DotNet core Runtime
專案中包含 Dockerfile & docker-compose.yml
docker-compose.yml
version: '3' # 目前使用的版本,可以參考官網
services:
dotnetproject:
build:
context: .
dockerfile: ./Dockerfile
image: ${company name}/${project name}:${version}
ports:
- 80:80
container_name: ${prefix}-${project name}-${type}
restart: always
Dockerfile
#Dotnet Core Runtime version 2.2 3.0 3.1
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
#建立工作目錄夾 Web
RUN mkdir /web
#將編譯好的程式打包進 docker image
ADD ./bin/Release/netcoreapp3.1/publish/ /web
WORKDIR /web
#加入環境變數
ENV ASPNETCORE_ENVIRONMENT=Development
#設定容器起來時執行
ENTRYPOINT [ "dotnet", "dotnetproject.dll"]
留言
張貼留言