Docker 下部署 .NET6 项目
- Docker
- 2024-03-27
- 30热度
- 0评论
右键项目,添加 Docker 支持
Dockerfile 文件内容(路径修改后):
#See https://aka.ms/customizecontainer to learn how to customize your debug container and 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 5194
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["WebApplication1.csproj", "./"]
RUN dotnet restore "./WebApplication1.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "WebApplication1.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebApplication1.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
#RUN cd /etc/apt
WORKDIR /etc/apt
# 备份
RUN mkdir sources.list.backup
RUN cp sources.list ./sources.list.backup
# 以覆盖+追加的方式替换掉sources.list文件
RUN echo 'deb https://mirrors.aliyun.com/debian bullseye main'>sources.list
RUN echo 'deb https://mirrors.aliyun.com/debian-security bullseye-security main'>>sources.list
RUN echo 'deb https://mirrors.aliyun.com/debian bullseye-updates main'>>sources.list
#RUN cat sources.list
RUN apt-get update -y
RUN apt-get install -y libgdiplus
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication1.dll"]
构建镜像:
docker build -t jzsoft.junliang.web .
运行容器:
docker run -d --name jzsoft.junliang.web -p 35091:35091 jzsoft.junliang.web
.net 6 项目在docker容器中添加 libgdiplus 依赖库的安装 https://blog.csdn.net/zhy810302/article/details/129455025
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ sid main contrib non-free" > /etc/apt/sources.list
RUN apt-get update && apt-get install -y apt-transport-https ca-certificates apt-utils libgdiplus libc6-dev && apt-get install -y libfreetype6 && apt-get install -y libfontconfig1 && apt-get install -y fontconfig

鲁ICP备19063141号
鲁公网安备 37010302000824号