Skip to content

Linux 部署

部署步骤

  1. 发布文件到文件夹选择Debug发布
  2. 添加Dockerfiledocker-compose.yml

Dockerfile

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS publish
WORKDIR /app
EXPOSE 8085
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN sed -i s@/deb.debian.org/@/mirrors.aliyun.com/@g /etc/apt/sources.list 
RUN apt-get clean 
RUN apt-get update
RUN apt-get install libgdiplus --assume-yes 
RUN apt-get install fontconfig
#RUN yum install mkfontscale 
#RUN mkfontscale
#RUN mkfontdir
#RUN fc-cache -fv
COPY . .
ENTRYPOINT ["dotnet", "xxxx.dll"]

docker-compose.yml

version: '3'
services:
  admincore:
    build: 
      context: . 
      dockerfile: Dockerfile 
    ports:
      - "8085:8085"
    volumes:
      - ./appsettings.json:/app/appsettings.json
      - ./Configs/:/app/Configs/
      - ./ConfigCenter:/app/ConfigCenter
      - ./nlogs/:/nlogs
      - ./upload/:/app/upload
    restart: always
  1. 发布文件下的所有内容上传到Linux目录
  2. 执行docker-compose up -d --build会自动编译并且自动运行一个实例
  3. 访问/admin/swagger/index.html能弹出swagger表示部署成功
  4. docker-compose down停止并删除容器,镜像还会在docker rmi删除镜像

提示

  1. 修改nlogupload的目录,所以docker-compose映射的目录会和大家的不一致,请按需配置
  2. 修改启动的端口这里用的是8085,会和大家的不一致,请按需配置
  3. 宿主机如果访问swagger不通,先查看docker logs的日志,如果没有问题,请确认端口是否打开