Deploy a C# Container Instance in Azure

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

使用Terraform on Azure 部署IronSecureDoc Docker容器,并通过公共IP地址和FQDN使其可用。

前提条件

安装和配置 Terraform

步骤 1:克隆 GitHub 仓库模板

我们已为您准备好 GitHub 仓库模板,您可以克隆并立即开始使用,链接如下:

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

步骤二:修改所有资源名称

在variables.tf中修改所有资源名称

  • resource_group_name:资源组的名称。
  • REGIONS.md找到区域,并使用第二列填充此变量。
  • container_group_name:容器组的名称。
  • container_name:容器的名称。
  • image_tag:要部署的镜像标签; 它可以是latest或任何特定的版本号。
  • 其他变量无需更改。

创建secret.tfvars以包含所有敏感数据

在secret.tfvars中填充以下变量。

Azure容器注册表

在main.tf中:

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

添加到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."
}
HCL

添加到secret.tfvars中:

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

Docker Hub

添加到secret.tfvars中:

license_key = "YOUR-LICENSE-KEY"
HCL

步骤 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

步骤六:验证结果

  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 创建和应用执行计划。

在 Azure 部署中设置 Terraform 的必要步骤是什么?

首先,安装并配置 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 计划和应用过程中引用,以安全管理敏感信息。

using Terraform 销毁 Azure 中已部署资源的过程是什么?

要使用 Terraform 销毁 Azure 中已部署的资源,请用 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 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

阅读更多

准备开始了吗?

版本:2024.10刚刚发布