新建项目testapi

docker 发布netcore webapi

新建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 发布netcore webapi

 

 新建容器: docker build -t testapi:dev .

docker 发布netcore webapi

运行容器:docker run --name testapi -p 8080:80 -d testapi:dev

执行:docker ps

docker 发布netcore webapi

 测试连接:curl http://localhost:8080/api/values

docker 发布netcore webapi

浏览器打开

docker 发布netcore webapi

发布完成

相关文章:

  • 2018-03-20
  • 2021-07-30
  • 2021-12-17
  • 2018-09-15
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-22
  • 2022-12-23
  • 2022-12-23
  • 2022-01-31
  • 2021-07-17
  • 2022-12-23
相关资源
相似解决方案