Dockerfile文件内容,可以用VS2019直接生成,注意COPY路径和存放位置。 #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/core/aspnet:3.1-buster-slim AS base WORKDIR /app EXPOSE 80 FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build WORKDIR /src COPY ["WebAPI/WebAPI.csproj", "WebAPI/"] COPY ["Common/Common.csproj", "Common/"] RUN dotnet restore "WebAPI/WebAPI.csproj" COPY . . WORKDIR "/src/WebAPI" RUN dotnet build "WebAPI.csproj" -c Release -o /app/build FROM build AS publish RUN dotnet publish "WebAPI.csproj" -c Release -o /app/publish FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "WebAPI.dll"] 拉取镜像
登录阿里云Docker Registry
$ sudo docker login --username=[你的阿里云用户名] registry.cn-qingdao.aliyuncs.com用于登录的用户名为阿里云账号全名,密码为开通服务时设置的密码。
您可以在访问凭证页面修改凭证密码。
从Registry中拉取镜像
查看镜像
[root@iZwz925p95hhdeZ ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE registry.cn-hangzhou.aliyuncs.com/zztnet/demo v1.0 fd54b8a9fc7b 4 days ago 232MB microsoft/dotnet latest 156e5cc5d7a3 3 weeks ago 1.74GB运行
$ sudo docker run -d -p 80:80 registry.cn-hangzhou.aliyuncs.com/zztnet/demo:v1.0