后端(netcore)容器化部署二件套
Dockerfile
vs生成,在里面增加时区配置
#环境变量设置时区
ENV TZ=Asia/Shanghai
*Dockerfile示例
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["Test.Web.Entry/Test.Web.Entry.csproj", "Test.Web.Entry/"]
COPY ["Test.Database.Migrations/Test.Database.Migrations.csproj", "Test.Database.Migrations/"]
COPY ["Test.DataBase.Core/Test.DataBase.Core.csproj", "Test.DataBase.Core/"]
COPY ["Test.Core/Test.Core.csproj", "Test.Core/"]
COPY ["Test.Infrastructure/Test.Infrastructure.csproj", "Test.Infrastructure/"]
COPY ["Test.Web.Core/Test.Web.Core.csproj", "Test.Web.Core/"]
COPY ["Test.Application/Test.Application.csproj", "Test.Application/"]
COPY ["Test.Repository/Test.Repository.csproj", "Test.Repository/"]
RUN dotnet restore "Test.Web.Entry/Test.Web.Entry.csproj"
COPY . .
WORKDIR "/src/Test.Web.Entry"
RUN dotnet build "Test.Web.Entry.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Test.Web.Entry.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
#环境变量设置时区
ENV TZ=Asia/Shanghai
ENTRYPOINT ["dotnet", "Test.Web.Entry.dll"]
docker-compose.yml
version: "3.9"
services:
testapi:
build:
context: ./
dockerfile: Test.Web.Entry/Dockerfile
image: testapi:latest
mem_limit: 512m
ports:
- "8077:80"
environment:
- ASPNETCORE_ENVIRONMENT=Development
- DataBase__RedisConnection=127.0.0.1:8379,password=123456,allowAdmin=true
networks:
- testwork
networks:
testwork:
external: false
name: testwork
jenkins执行命令
docker-compose -f docker-compose.yml up -d --build
jenkins git配置


浙公网安备 33010602011771号