今天的筆記要來介紹應用程式升級, 以下的簡單幾個步驟可以完成應用程式的升級與部署.
About.cshtml
, 修改 About page 原始碼 (加入第 6 行)<div><h1 class="display-4">@Environment.MachineName</h1></div>
2. 使用命令 docker build . -t 15maksacr.azurecr.io/aspnetapp:v2
重新編譯 image, 並且指派 tag: aspnetapp:v2
PS C:\k8s\dotnet-docker\samples\aspnetapp> docker build . -t 15maksacr.azurecr.io/a
spnetapp:v2
Sending build context to Docker daemon 2.469MB
Step 1/12 : FROM microsoft/dotnet:2.1-sdk AS build
---> efa6f1f55357
Step 2/12 : WORKDIR /app
---> Using cache
---> 4e06e9e16269
Step 3/12 : COPY *.sln .
---> Using cache
---> 57ed7afde34f
Step 4/12 : COPY aspnetapp/*.csproj ./aspnetapp/
---> Using cache
---> 1039eace2122
Step 5/12 : RUN dotnet restore
---> Using cache
---> 842f61672f26
Step 6/12 : COPY aspnetapp/. ./aspnetapp/
---> 8c6255f8258f
Step 7/12 : WORKDIR /app/aspnetapp
---> Running in 52aa12001d28
Removing intermediate container 52aa12001d28
---> b89bd8fecabe
Step 8/12 : RUN dotnet publish -c Release -o out
---> Running in 6c478e1f2970
Microsoft (R) Build Engine version 15.8.169+g1ccb72aefa for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 452 ms for /app/aspnetapp/aspnetapp.csproj.
aspnetapp -> /app/aspnetapp/bin/Release/netcoreapp2.1/aspnetapp.dll
aspnetapp -> /app/aspnetapp/bin/Release/netcoreapp2.1/aspnetapp.Views.dll
aspnetapp -> /app/aspnetapp/out/
Removing intermediate container 6c478e1f2970
---> 2fd74610e0f5
Step 9/12 : FROM microsoft/dotnet:2.1-aspnetcore-runtime AS runtime
---> 70c1124a9a02
Step 10/12 : WORKDIR /app
---> Using cache
---> 2d237448f63a
Step 11/12 : COPY --from=build /app/aspnetapp/out ./
---> 834717d46153
Step 12/12 : ENTRYPOINT ["dotnet", "aspnetapp.dll"]
---> Running in f71260af785d
Removing intermediate container f71260af785d
---> d9b92c011931
Successfully built d9b92c011931
Successfully tagged 15maksacr.azurecr.io/aspnetapp:v2
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.
PS C:\k8s\dotnet-docker\samples\aspnetapp> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
15maksacr.azurecr.io/aspnetapp v2 d9b92c011931 49 seconds ago 257MB
<略…>
PS C:\k8s\dotnet-docker\samples\aspnetapp> az acr login -n 15maksacr
Login Succeeded
15maksacr.azurecr.io/aspnetapp:v2
將 image 推送到 ACR 中PS C:\k8s\dotnet-docker\samples\aspnetapp> docker push 15maksacr.azurecr.io/aspnetapp:v2
The push refers to repository [15maksacr.azurecr.io/aspnetapp]
41ed3afe8148: Pushed
cd1be85f4c90: Layer already exists
d00d2c8144b6: Layer already exists
108fa49df6c1: Layer already exists
ddd4c04722d5: Layer already exists
8b15606a9e3e: Layer already exists
v2: digest: sha256:67486f49131a12b5c554a157fc80dc20ba1a89d17bdb99b9b0195c200783539e size: 1580
PS C:\k8s\dotnet-docker\samples\aspnetapp> kubectl apply -f .\aspnetapp-deployment.y
ml
deployment.apps "aspnetapp-deployment" created
service "aspnetapp-service" created
以上便完成了更新應用程式囉!