IRONSOFTWAREHOME

Deploy a C# Container Instance in Azure

Curtis Chau
Curtis Chau
Updated: 2026年5月9日

使用Azure上的Terraform來部署IronSecureDoc Docker容器,並使用公共IP地址和FQDN使其可用。

先決條件

步驟1:克隆GitHub儲存庫範本

我們已經準備好了GitHub儲存庫範本,您可以立即克隆並開始:

https://github.com/iron-software/IronSecureDoc-Terraform/
Text

步驟2:修改所有資源名稱

在variables.tf中修改所有資源名稱

  • resource_group_name:資源群組的名稱。
  • REGIONS.md查找區域,並使用第二列填寫此變數。
  • container_group_name:容器群組的名稱。
  • container_name:容器的名稱。
  • image_tag:要部署的映像標籤; 可以是latest或任何特定的版本號。
  • 其他變數不需要更改。

建立secret.tfvars來存放所有敏感資料

在secret.tfvars中填寫以下變數。

Azure容器註冊表

在dns_name_label = var.dns_name_label:

image_registry_credential {
  server   = var.registry_server
  username = var.registry_username
  password = var.registry_password
}
Text

新增到variables.tf:

variable "registry_server" {
  type        = string
  sensitive   = false
  description = "The server for the container registry. Required if the image is stored in a private registry."
}

variable "registry_username" {
  type        = string
  sensitive   = true
  description = "Username for the container registry. Required if the image is stored in a private registry."
}

variable "registry_password" {
  type        = string
  sensitive   = true
  description = "Password for the container registry. Required if the image is stored in a private registry."
}
Text

新增到secret.tfvars:

registry_server   = "<registry-name>.azurecr.io"
registry_username = "YOUR-REGISTRY-USERNAME"
registry_password = "YOUR-REGISTRY-PASSWORD"
license_key       = "YOUR-LICENSE-KEY"
Text

Docker Hub

新增到secret.tfvars:

license_key = "YOUR-LICENSE-KEY"
Text

步驟3:初始化Terraform

運行terraform init來初始化Terraform部署。 此命令下載管理Azure資源所需的Azure提供者。

terraform init -upgrade
SHELL

步驟4:建立Terraform執行計畫

運行terraform plan來建立執行計畫。

terraform plan -var-file="secret.tfvars" -out main.tfplan
SHELL

步驟5:應用Terraform執行計畫

運行terraform apply來將執行計畫應用到您的雲基礎設施。

terraform apply main.tfplan
SHELL

步驟6:驗證結果

  1. 當您應用執行計畫時,Terraform會輸出公共IP地址。 要再次顯示IP地址,請運行terraform output。

    terraform output -raw container_ipv4_address
    SHELL

    或顯示FQDN。

    terraform output -raw container_fqdn
    SHELL
  2. 使用Postman或curl進行驗證。 預期結果應返回pong。

    curl http://<container_ipv4_address>:8080/v1/document-services/ping
    SHELL

    或使用FQDN。

    curl http://<container_fqdn>:8080/v1/document-services/ping
    SHELL

步驟7:銷毀資源

  • 為銷毀資源建立執行計畫。

    terraform plan -destroy -var-file="secret.tfvars" -out main.tfplan
    SHELL
  • 應用執行銷毀計畫。

    terraform apply main.tfplan
    SHELL

常見問題

如何使用Terraform在Azure中部署Docker容器?

要使用Terraform在Azure中部署Docker容器,您需要克隆IronSecureDoc的GitHub資料庫範本,修改`variables.tf`中的資源名稱,並建立包含敏感資料的`secret.tfvars`文件。然後,使用terraform init初始化部署,並使用terraform plan和terraform apply建立和應用執行計畫。

設置Terraform以進行Azure部署的必要步驟是什麼?

首先,安裝並配置Terraform,然後將其身份驗證到Azure。克隆IronSecureDoc的特定GitHub資料庫,修改`variables.tf`文件中的資源名稱,並在`secret.tfvars`中管理敏感資料。最後,初始化Terraform並建立部署的執行計畫。

在此部署中,Azure容器註冊表的角色是什麼?

Azure容器註冊表用於儲存Docker映像。您需要在`main.tf`文件中附加註冊表憑證,並在`variables.tf`和`secret.tfvars`中指定註冊表資訊,以便部署存取和部署所需的Docker映像。

如何確認我的Terraform部署在Azure中是否成功?

應用Terraform執行計畫後,運行terraform output獲取公眾IP地址或FQDN。使用Postman或curl等工具發送ping請求給服務。成功部署會返回'pong'。

用於初始化Azure部署的Terraform的命令是什麼?

要初始化Azure部署的Terraform,請使用命令terraform init -upgrade。這會下載管理Azure資源所需的提供者插件。

如何在Terraform配置中處理敏感資料?

諸如註冊表憑證和授權金鑰之類的敏感資料應儲存在`secret.tfvars`文件中。在Terraform計畫與應用過程中參考此文件以安全地管理敏感資訊。

使用Terraform在Azure中銷毀已部署的資源的過程是什麼?

要在Azure中使用Terraform銷毀已部署的資源,使用terraform plan -destroy -var-file='secret.tfvars' -out main.tfplan建立銷毀執行計畫並使用terraform apply main.tfplan應用它。

How can I verify the deployment of the IronSecureDoc container?

You can verify the deployment by running `terraform output` to obtain the public IP or FQDN and using tools like Postman or `curl` to execute a ping, expecting a `pong` response.

What is the process to destroy the IronSecureDoc resources on Azure?

To destroy the resources, create a destroy execution plan with `terraform plan -destroy` and then apply it using `terraform apply` to remove IronSecureDoc resources from Azure.

Can I specify the tag of the IronSecureDoc Docker image during deployment?

Yes, you can specify the tag of the IronSecureDoc Docker image by setting the `image_tag` variable in the `variables.tf` file, using either `latest` or a specific version number.

Curtis Chau
技術作家

Curtis Chau擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。

...
閱讀更多

準備開始了嗎?

版本:2024.10剛剛發布

立即獲取您的免費 30天試用金鑰。
無需信用卡或帳戶建立
Key in blue circle

立即免費取得 30 天試用金鑰。

Your trial license will be sent to your email address

無任何限制。100% 解鎖。無需信用卡。

OR
bullet_checked無需信用卡或建立帳號無任何限制。100% 解鎖。無需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried Iron Suite
預訂您的免費 即時演示
Booking Badge

全球數百萬工程師的信任

Iron Software的客戶標誌
獲取您的無義務諮詢
完成下列表單或發送電子郵件至 sales@ironsoftware.com
您的資訊將始終保密。
全球數百萬工程師的信任
Iron Software的客戶標誌
立即獲取您的30天試用金鑰。
無需信用卡或帳戶建立