[root@VM-12-3-centos DockerWeb]# docker build -t docker-web . Sending build context to Docker daemon 13.82kB Step 1/17 : FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base 6.0: Pulling from dotnet/aspnet a2abf6c4d29d: Already exists 08af7dd3c640: Pull complete 742307799914: Pull complete a260dbcd03fc: Pull complete 96c3c696f47e: Pull complete Digest: sha256:7696d5b456eede87434c232b9070f40659ff0c4b71ca622cf197815ccaee661d Status: Downloaded newer image for mcr.microsoft.com/dotnet/aspnet:6.0 ---> 8d32e18b77a4 Step 2/17 : WORKDIR /app ---> Running in e6c17cf8d13c Removing intermediate container e6c17cf8d13c ---> a572d041e0da Step 3/17 : EXPOSE 80 ---> Running in d13e67c50b6d Removing intermediate container d13e67c50b6d ---> bbbbe840e85e Step 4/17 : EXPOSE 443 ---> Running in 567ce4adadc9 Removing intermediate container 567ce4adadc9 ---> dfc3eb0c4065 Step 5/17 : FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build 6.0: Pulling from dotnet/sdk a2abf6c4d29d: Already exists 08af7dd3c640: Already exists 742307799914: Already exists a260dbcd03fc: Already exists 96c3c696f47e: Already exists d81364490ceb: Pull complete 3e56f7c4d95f: Pull complete 9939dbdaf4a7: Pull complete Digest: sha256:a7af03bdead8976d4e3715452fc985164db56840691941996202cea411953452 Status: Downloaded newer image for mcr.microsoft.com/dotnet/sdk:6.0 ---> e86d68dca8c7 Step 6/17 : WORKDIR /src ---> Running in b3db267dfde3 Removing intermediate container b3db267dfde3 ---> 1e44b66e7fcc Step 7/17 : COPY ["DockerWeb.csproj", "."] ---> 7af02dfd823e Step 8/17 : RUN dotnet restore "./DockerWeb.csproj" ---> Running in 22c508e5bfb8 Determining projects to restore... Restored /src/DockerWeb.csproj (in 3.04 sec). Removing intermediate container 22c508e5bfb8 ---> 530712ad2cb4 Step 9/17 : COPY . . ---> 9f72854995f8 Step 10/17 : WORKDIR "/src/." ---> Running in 4a4a8225dd93 Removing intermediate container 4a4a8225dd93 ---> b60fdb650fdc Step 11/17 : RUN dotnet build "DockerWeb.csproj" -c Release -o /app/build ---> Running in a49f8a39451c Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore... All projects are up-to-date for restore. DockerWeb -> /app/build/DockerWeb.dll
Build succeeded. 0 Warning(s) 0 Error(s)
Time Elapsed 00:00:02.92 Removing intermediate container a49f8a39451c ---> 58c5a002da43 Step 12/17 : FROM build AS publish ---> 58c5a002da43 Step 13/17 : RUN dotnet publish "DockerWeb.csproj" -c Release -o /app/publish ---> Running in b60058485f34 Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore... All projects are up-to-date for restore. DockerWeb -> /src/bin/Release/net6.0/DockerWeb.dll DockerWeb -> /app/publish/ Removing intermediate container b60058485f34 ---> c5456b5f5ad1 Step 14/17 : FROM base AS final ---> dfc3eb0c4065 Step 15/17 : WORKDIR /app ---> Running in cf76a79268ee Removing intermediate container cf76a79268ee ---> 6a0b49e53f4a Step 16/17 : COPY --from=publish /app/publish . ---> acf5b1cb9f98 Step 17/17 : ENTRYPOINT ["dotnet", "DockerWeb.dll"] ---> Running in da2fa62b807b Removing intermediate container da2fa62b807b ---> bb42b5515f09 Successfully built bb42b5515f09 Successfully tagged docker-web:latest
镜像构建成功后,便可以在镜像中找到我们构建的镜像
1 2 3
[root@VM-12-3-centos DockerWeb]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker-web latest bb42b5515f09 2 minutes ago 212MB
启动镜像
1 2
docker run -d --name docker-web -p 8880:80 docker-web