1.新建webapi接口net7項目
2.設置docker支持
3.本地要安裝docker
window 安裝docker desktop https://docs.docker.com/desktop/
4.右鍵終端打開項目
5.查看docker 版本
6.配置dockerfile
dotnet restore
命令使用 NuGet 還原依賴項以及在 project 文件中指定的特定於項目的工具
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base WORKDIR /app EXPOSE 5005 ENV ASPNETCORE_ENVIRONMENT=Development ENV ASPNETCORE_URLS http://+:5005 FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build WORKDIR /src COPY ["Dev.DockerTest.csproj", "./"] RUN dotnet restore "./Dev.DockerTest.csproj" COPY . . WORKDIR "/src/." RUN dotnet build "Dev.DockerTest.csproj" -c Release -o /app/build FROM build AS publish RUN dotnet publish "Dev.DockerTest.csproj" -c Release -o /app/publish /p:UseAppHost=false FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "Dev.DockerTest.dll"]
docker build -t dockertest .
7.騰訊雲創建個人鏡像服務
根據提示操作
終端切換登錄
docker login --username=xxx ccr.ccs.tencentyun.com
打包鏡像
docker tag eeaf3e107fdf ccr.ccs.tencentyun.com/mytxspace/dockertest:v1
push
docker push ccr.ccs.tencentyun.com/mytxspace/dockertest:v1
7.docker 拉取鏡像
docker pull ccr.ccs.tencentyun.com/mytxspace/dockertest:v1
8.docker run 鏡像
docker run -itd --name dockertest -p 5004:5005 ccr.ccs.tencentyun.com/mytxspace/dockertest:v1