docker部署.NET6并挂载目录

1: 创建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 8075 
#8075需要和appsettings.json文件中的配置的端口保持一致

#设置时区
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# 复制所有文件到工作目录
COPY . .

# 设置运行时的启动命令  test.dll填写你自己项目的dll
ENTRYPOINT ["dotnet", "test.dll"]

 2: 构建并运行Docker容器,挂载代码目录

# 构建Docker镜像
docker build -t test .

# 运行容器,挂载你的代码目录到容器内的/app目录  在这里,/path/to/your/code应该替换为你的本地代码目录的路径。这样,当你修改本地代码时,容器内的应用将自动更新,无需重新构建镜像
docker run -d -p 8075:8075 --name yourappcontainer -v /path/to/your/code:/app yourappname

 

posted @ 2025-02-25 17:12  斌言  阅读(27)  评论(0)    收藏  举报