首先第一步需要在系统中成功安装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
网站中有很多比较实用的在线小工具,另外也欢迎大家提出宝贵的意见。