You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Terraform中为Azure ACI的OSM瓦片容器传递命令

在Azure ACI部署openstreetmap-tile-server时传递命令的解决方案

问题背景

使用Terraform将overv/openstreetmap-tile-server镜像部署到Azure容器实例(ACI)时,无法正确传递import或run命令,尝试两种配置均报错:

  • 配置commands = ["/bin/bash", "-c", "import"]时,提示/bin/bash: line 1: import: command not found
  • 直接配置commands = ["import"]并添加下载环境变量时,提示exec: "run": executable file not found in $PATH

错误原因

  1. import/run不是系统全局可执行命令,而是镜像内置入口脚本/run.sh的参数,通过bash直接调用会找不到命令
  2. 镜像默认启动逻辑为执行/run.sh run,仅指定参数时可能出现ACI容器启动的参数传递异常

正确配置方式

直接在commands中指定完整的入口脚本路径加目标参数,明确让容器执行/run.sh import(初始化数据)或/run.sh run(启动服务)。

修改后的容器配置片段

container {
  name   = "maps"
  image  = "overv/openstreetmap-tile-server"
  cpu    = "2"
  memory = "16"

  # 选择对应命令:初始化用import,启动服务用run
  commands = ["/run.sh", "import"]

  # 可选:添加环境变量配置下载源、线程数等
  environment_variables = {
    DOWNLOAD_PBF="https://download.geofabrik.de/europe/luxembourg-latest.osm.pbf"
    DOWNLOAD_POLY="https://download.geofabrik.de/europe/luxembourg.poly"
    THREADS="4" # 根据CPU核数调整,提升导入/渲染效率
  }

  ports {
    port     = 80
    protocol = "TCP"
  }

  # 挂载存储共享的配置(保持原配置即可)
  volume {
    name       = "osm-data"
    mount_path = "/data/database/"
    read_only  = false
    share_name = azurerm_storage_share.example.name
    storage_account_name = azurerm_storage_account.example.name
    storage_account_key  = azurerm_storage_account.example.primary_access_key
  }

  volume {
    name       = "osm-tiles"
    mount_path = "/data/tiles/"
    read_only  = false
    share_name = azurerm_storage_share.examplee.name
    storage_account_name = azurerm_storage_account.example.name
    storage_account_key  = azurerm_storage_account.example.primary_access_key
  }
}

额外注意事项

  • import是一次性初始化命令,执行完成后容器会自动退出,因此restart_policy设为Never合理;若后续要启动服务,需修改commands为["/run.sh", "run"],并将restart_policy改为Always或OnFailure
  • 确保挂载的存储共享配额足够,OSM数据导入需要较大磁盘空间

内容的提问来源于stack exchange,提问作者Mroczny Arturek

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 02:42:08