在windows系统中使用docker部署.net项目

首先第一步需要在系统中成功安装docker,直接官网下载最新版本安装即可
其次在项目中右键》添加docker支持
会生成一个dockerfile文件
其中的配置如下

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

#Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed.
#For more information, please see https://aka.ms/containercompat

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["test/test.csproj", "test/"]
RUN dotnet restore "test/test.csproj"
COPY . .
WORKDIR "/src/test"
RUN dotnet build "test.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "test.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "test.dll"]

然后在命令行工具cmd中跳转到项目所在的文件夹
输入dos命令

docker build -t net5test123 -f Dockerfile ..

-t 后面是镜像的名字
… 2点表示上级目录,这里根据你的目录来定的,上两级目录开始打包就是2个点,上一级目录就是1个点
命令执行成功之后可以输入

docker images

查看镜像。
最后执行

docker run --name net5123 -d -p 8088:80 net5test123

启动镜像就可以了。
这里的 8088:80 表示用计算机的8088端口去映射docker中的80端口。
然后在浏览器中输入相应的地址加端口就可以访问了。

这里到最后,分享一个工具网站 https://www.ykstool.cn
网站中有很多比较实用的在线小工具,另外也欢迎大家提出宝贵的意见。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值