06.Ty.Api为例
1.完整重新生成代码 and 发布到docker
FROM mcr.microsoft.com/dotnet/sdk:7.0 as build-env
WORKDIR /06.Ty.Api
COPY 06.Ty.Api/*csproj .
RUN dotnet restore
COPY . .
# RUN dotnet publish -c Release -o /publish
RUN dotnet publish 06.Ty.Api/06.Ty.Api.csproj -c Release -o /publish
FROM mcr.microsoft.com/dotnet/aspnet:7.0 as runtime
RUN rm -f /etc/localtime && ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone
WORKDIR /src
COPY --from=build-env /publish .
ENV ASPNETCORE_URLS=http://+:80
EXPOSE 80
ENTRYPOINT [ "dotnet","Ty.Api.dll" ]
2.简易版 只把生成文件发布到docker
FROM mcr.microsoft.com/dotnet/aspnet:7.0 as runtime
RUN rm -f /etc/localtime && ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone
WORKDIR /src
COPY /bin/publish .
ENV ASPNETCORE_URLS=http://+:80
EXPOSE 80
ENTRYPOINT [ "dotnet","Ty.Api.dll" ]
3.docker 运行命令
docker build --tag ty.web.api .
docker run -d -p 7000:80 --name=ty.web.api.01 ty.web.api