iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 14
1
Microsoft Azure

深入 Azure 雲端服務系列 第 11

Azure Docker - 使用 WSL2 管理/開發 Azure 資源

接下來開始會需要完整的 docker 環境來做開發跟管理

首先需要安裝 WSL2 (網路上很多環境架設文章,這邊就不多著墨),安裝 Linux 環境筆者這邊選擇 Ubuntu ,接著在 WSL2 裡面安裝 Azure CLI

方式 : 在 WSL 執行 sudo apt install azure-cli 即可

https://user-images.githubusercontent.com/12729184/94571900-03b43a80-02a3-11eb-9907-b967535d8375.png

登入 > 配合 bash uuidgen 創建一個測試 ACR

az login
az acr create --resource-group demo --name $(uuidgen | tr -d '-')  --sku Basic

https://user-images.githubusercontent.com/12729184/94572703-e59b0a00-02a3-11eb-8beb-183ad07f1e55.png

像這一點 Azure Cloud Shell 就不做到,雖然其有 Ubuntu 環境但沒有 root 權限

https://user-images.githubusercontent.com/12729184/94573057-4b879180-02a4-11eb-97c2-affcdca789ef.png

測試 hello world 專案是否能推送到 ACR 並且運行

echo FROM hello-world > Dockerfile 
az acr build --image sample/hello-world:v1 --registry 42556f4129fb4c5db21e365ea2770211 --file Dockerfile .
az acr run --registry 42556f4129fb4c5db21e365ea2770211 --cmd '$Registry/sample/hello-world:v1' /dev/null

https://user-images.githubusercontent.com/12729184/94573704-eda77980-02a4-11eb-9b0e-96a125bd9233.png

https://user-images.githubusercontent.com/12729184/94573766-fc8e2c00-02a4-11eb-813b-e137baea5463.png

甚至我們可以在 WSL2 執行 code .在 windows 10 的VSCode 編輯 ubuntu 內檔案,像是直接在其編輯 ARM Template

https://user-images.githubusercontent.com/12729184/94575447-d49fc800-02a6-11eb-8666-3111b7f4673c.png

並可做到 Azure CLI + 傳遞參數給 ARM Template 外加搭配 uuidgen + cut 功能,不用動用 powershell 即可創建隨機唯一值,非常方便 !

az group deployment create --resource-group demo --template-file demoTemplate.json --parameters "{ \"storageName\": { \"value\": \"$(uuidgen | tr -d '-' | cut -c1-24)\" } }"

https://user-images.githubusercontent.com/12729184/94576650-272db400-02a8-11eb-820b-b89f805a64d0.png


上一篇
Azure CLI + Powershell + ARM Template + Docker 整合從無到有快速布置網頁
下一篇
Azure Docker - 在WSL2寫網頁打包上傳ACR建立WebAPP
系列文
深入 Azure 雲端服務15
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言