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

Azure ACI中挂载settings_local.py文件至容器的方法咨询

在Azure ACI中挂载chessmasterrr/bitpoll的settings_local.py文件的可行方案

方法1:Azure文件共享挂载(持久化存储,适合长期使用)

这是最稳定的方案,配置后文件会持久保存在Azure存储中,容器重启或重建后配置不会丢失。

  • 创建Azure存储账户和文件共享:
    1. 确保存储账户与ACI部署在同一区域,避免跨区域延迟。
    2. 在存储账户的「文件服务」中新建一个共享(例如命名为bitpoll-config)。
    3. 将本地的settings_local.py上传到该文件共享的根目录。
  • 部署ACI时配置挂载:
    使用Azure CLI执行以下命令(替换占位符为你的实际信息):
    az container create \
      --resource-group <你的资源组名称> \
      --name bitpoll-instance \
      --image chessmasterrr/bitpoll \
      --azure-file-volume-account-name <存储账户名称> \
      --azure-file-volume-account-key <存储账户访问密钥> \
      --azure-file-volume-share-name bitpoll-config \
      --azure-file-volume-mount-path /Bitpoll/bitpoll/
    
    注意:挂载路径指定为容器内的/Bitpoll/bitpoll/目录,文件共享中的settings_local.py会被映射到该目录下,自动覆盖容器原有的同名文件(如果存在)。

方法2:ACI Secret挂载单个文件(无持久化,适合临时测试)

如果不需要持久化配置,可以将文件内容作为Secret挂载到容器中:

  • 编码配置文件:
    本地将settings_local.py内容转为Base64编码:
    • Linux/macOS终端:
      base64 -i settings_local.py > settings_local.b64
      
    • Windows PowerShell:
      [Convert]::ToBase64String([IO.File]::ReadAllBytes(".\settings_local.py")) | Out-File -Encoding ASCII settings_local.b64
      
  • 部署ACI并挂载Secret:
    执行以下Azure CLI命令:
    az container create \
      --resource-group <你的资源组名称> \
      --name bitpoll-instance \
      --image chessmasterrr/bitpoll \
      --secrets settings_local.py=$(cat settings_local.b64) \
      --secret-mounts source=settings_local.py,target=/Bitpoll/bitpoll/settings_local.py
    
    这里通过--secret-mounts直接将Secret内容挂载为容器内的指定文件,路径必须精确到文件名。

常见问题排查

  • 验证容器内路径:登录到ACI容器检查文件是否存在及权限:
    az container exec --resource-group <资源组名称> --name bitpoll-instance --exec-command "/bin/bash"
    
    进入容器后执行ls -l /Bitpoll/bitpoll/settings_local.py,确认文件存在且权限为可读(至少r--权限)。
  • 文件共享权限检查:如果使用文件共享,确保存储账户的防火墙规则允许ACI所在网络访问(可临时设置为「允许所有网络」测试),同时确认存储账户密钥输入正确。
  • 配置文件内容检查:确保settings_local.py的语法符合Python规范,没有语法错误导致容器启动失败。

内容的提问来源于stack exchange,提问作者Knut Niehaus

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 20:55:21