• Docker-.Net Core部署


    微服务项目中,通过Docker发布项目,操作步骤大致如下:
    1.Docker环境
    (1)root登陆虚拟机
    su -
    确保 yum 包更新到最新
    yum update
     
    (2)卸载旧版本
    yum remove docker docker-common docker-selinux docker-engine
     
    (3)安装需要的安装包
    yum install -y yum-utils
    更新yum 索引安装包
    yum makecache fast
     
    (4)设置镜像仓库
    yum-config-manager
    --add-repo
    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
     
    (5)Docker相关包安装
    yum install docker-ce docker-ce-cli containerd.io
     
    (6)启动Docker
    systemctl start docker
    查看docker 是否安装完成
    docker --version
    2.项目创建
    创建.Net Core MVC项目,勾选Docker,项目中生成DockerFile文件
    Dockerfile内容如下:
     1 #See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
     2 
     3 FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
     4 WORKDIR /app
     5 EXPOSE 80
     6 EXPOSE 443
     7 
     8 FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
     9 WORKDIR /src
    10 COPY ["test.csproj", "test/"]
    11 RUN dotnet restore "./test.csproj"
    12 COPY . .
    13 WORKDIR "/src/."
    14 RUN dotnet build "test.csproj" -c Release -o /app/build
    15 
    16 FROM build AS publish
    17 RUN dotnet publish "test.csproj" -c Release -o /app/publish
    18 
    19 FROM base AS final
    20 WORKDIR /app
    21 COPY --from=publish /app/publish .
    22 ENTRYPOINT ["dotnet", "test.dll"]
     
    3.远程部署
    通过Xftp远程Linux,把上述项目文件拷贝到系统文件下

     

     

    4.项目运行
    docker run -itd -p 端口名称:80 项目名称
    docker build -t 项目名称 -f Dockerfile .
     
    本次实例项目名称:test01,端口号:8082
     
    进入test文件夹:
    docker build -t test01 -f Dockerfile .
    注:Dockerfile后面有个点“.”

    docker run -itd -p 8082:80 test01
    项目运行结果如下:

    以上仅用于学习和总结!
     
    附:
    项目源码:
    链接:https://pan.baidu.com/s/1Yfa-Y1ryMB_5diSZgS_R2A
    提取码:37qi
     
    Xftp下载地址:
    链接:https://pan.baidu.com/s/1Iw2QxKduixa60knmQ572jA
    提取码:sd00

  • 相关阅读:
    log4net Appenders
    cnblogs 安家了
    log4net 资源索引贴
    Log2Console A Generic Log Viewer (for Log4Net, NLog...)
    [前端技术]如何加深对JavaScipt中的Math.ceil() 、Math.floor() 、Math.round() 三个函数的理解
    msiexec 命令使用文档
    “安装和部署”文章索引
    一句SQL实现获取自增列操作
    MsChart 部署遇到的一点问题
    [Asp.net]ZipHelper 在线压缩解压帮助类(SharpZipLib组件实现)
  • 原文地址:https://www.cnblogs.com/ywkcode/p/14405900.html
Copyright © 2020-2023  润新知