新建项目testapi
新建Dockerfile 文件
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-nanoserver-1809 AS base WORKDIR /app EXPOSE 80 EXPOSE 443 FROM mcr.microsoft.com/dotnet/core/sdk:2.2-nanoserver-1809 AS build WORKDIR /src COPY ["testapi.csproj", ""] RUN dotnet restore "./testapi.csproj" COPY . . WORKDIR "/src/." RUN dotnet build "testapi.csproj" -c Release -o /app FROM build AS publish RUN dotnet publish "testapi.csproj" -c Release -o /app FROM base AS final WORKDIR /app COPY --from=publish /app . ENTRYPOINT ["dotnet", "testapi.dll"]
在项目目录 ctrl+shift 鼠标右键 选择 在此处打开PowrShell
新建容器: docker build -t testapi:dev .
运行容器:docker run --name testapi -p 8080:80 -d testapi:dev
执行:docker ps
测试连接:curl http://localhost:8080/api/values
浏览器打开
发布完成