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

Docker Compose部署Netbox报错:depends_on需为数组类型

环境信息
  • 操作系统:Debian Bullseye
  • Docker版本:20.10.5+dfsg1,构建版本55c4c88
  • Docker-Compose版本:1.25.0
  • Docker-Py版本:4.1.0
  • CPython版本:3.9.2
  • OpenSSL版本:1.1.1n 2022年3月15日
问题详情

执行docker-compose pull命令时触发以下错误:

ERROR: The Compose file './docker-compose.yml' is invalid because:
services.netbox-housekeeping.depends_on contains an invalid type, it should be an array
services.netbox-worker.depends_on contains an invalid type, it should be an array

用户使用的docker-compose.yml内容如下:

version: "3.4"
services:
  netbox: &netbox
    image: netboxcommunity/netbox:${VERSION-v3.4-2.4.0}
    depends_on:
    - postgres
    - redis
    - redis-cache
    env_file: env/netbox.env
    user: "unit:root"
    healthcheck:
      start_period: 60s
      timeout: 3s
      interval: 15s
      test: "curl -f http://localhost:8080/api/ || exit 1"
    volumes:
    - ./configuration:/etc/netbox/config:z,ro
    - ./reports:/etc/netbox/reports:z,ro
    - ./scripts:/etc/netbox/scripts:z,ro
    - netbox-media-files:/opt/netbox/netbox/media:z
  netbox-worker:
    <<: *netbox
    depends_on:
      netbox:
        condition: service_healthy
    command:
    - /opt/netbox/venv/bin/python
    - /opt/netbox/netbox/manage.py
    - rqworker
    healthcheck:
      start_period: 20s
      timeout: 3s
      interval: 15s
      test: "ps -aux | grep -v grep | grep -q rqworker || exit 1"
  netbox-housekeeping:
    <<: *netbox
    depends_on:
      netbox:
        condition: service_healthy
    command:
    - /opt/netbox/housekeeping.sh
    healthcheck:
      start_period: 20s
      timeout: 3s
      interval: 15s
      test: "ps -aux | grep -v grep | grep -q housekeeping || exit 1"

  # postgres
  postgres:
    image: postgres:15-alpine
    env_file: env/postgres.env
    volumes:
    - netbox-postgres-data:/var/lib/postgresql/data

  # redis
  redis:
    image: redis:7-alpine
    command:
    - sh
    - -c # 用于读取环境变量中的REDIS_PASSWORD
    - redis-server --appendonly yes --requirepass $$REDIS_PASSWORD ## 双$是docker-compose的转义写法
    env_file: env/redis.env
    volumes:
    - netbox-redis-data:/data
  redis-cache:
    image: redis:7-alpine
    command:
    - sh
    - -c # 用于读取环境变量中的REDIS_PASSWORD
    - redis-server --requirepass $$REDIS_PASSWORD ## 双$是docker-compose的转义写法
    env_file: env/redis-cache.env
    volumes:
    - netbox-redis-cache-data:/data

volumes:
  netbox-media-files:
    driver: local
  netbox-postgres-data:
    driver: local
  netbox-redis-data:
    driver: local
  netbox-redis-cache-data:
    driver: local
问题原因与解决方法

原因

Docker Compose 1.25.0属于旧版V1分支,不支持depends_on字段中带condition的对象格式(该特性需要Compose文件格式3.8+及新版Compose运行时支持),旧版仅接受数组格式的服务名列表。

解决方案

有两种可行方案:

方案1:修改Compose文件适配旧版

将netbox-worker和netbox-housekeeping的depends_on改为数组格式,放弃健康检查依赖逻辑(旧版不支持该特性):

netbox-worker:
  <<: *netbox
  depends_on:
    - netbox
  command:
  - /opt/netbox/venv/bin/python
  - /opt/netbox/netbox/manage.py
  - rqworker
  healthcheck:
    start_period: 20s
    timeout: 3s
    interval: 15s
    test: "ps -aux | grep -v grep | grep -q rqworker || exit 1"
netbox-housekeeping:
  <<: *netbox
  depends_on:
    - netbox
  command:
  - /opt/netbox/housekeeping.sh
  healthcheck:
    start_period: 20s
    timeout: 3s
    interval: 15s
    test: "ps -aux | grep -v grep | grep -q housekeeping || exit 1"

方案2:升级Docker Compose到新版

升级到支持条件依赖的Compose版本(如2.0+),即可保留原有配置。在Debian Bullseye上执行以下命令:

# 卸载旧版docker-compose
sudo apt remove -y docker-compose
# 下载最新版docker-compose
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# 添加执行权限
sudo chmod +x /usr/local/bin/docker-compose
# 验证版本
docker-compose --version

内容的提问来源于stack exchange,提问作者J-B02

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 05:27:25