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

Docker Swarm部署报错:restart-policy属性不被允许的问题排查

Docker Stack Deploy Error: "Additional property restart-policy is not allowed"

The Issue

You’re hitting a syntax mismatch in your Docker Compose v3 file for Swarm mode deployment. The error pops up because you used the hyphenated restart-policy key under the deploy section—this doesn’t align with the required naming rules for Swarm-specific configuration fields.

The Fix

Update your docker-compose.yml to use the underscore-separated restart_policy key instead:

version: '3'
services:
  postgres:
    image: fleetit-postgres
    deploy:
      restart_policy:  # Correct key name (underscore, not hyphen)
        condition: on-failure
    ports:
      - "5432:5432"
    environment:
      POSTGRES_USER: "root"
      POSTGRES_PASSWORD: "demo1234"
      POSTGRES_DB: "fleetit"

Why This Works

For Docker Compose v3 (used for Swarm stack deployments), all sub-fields under the deploy section follow underscore-based naming conventions. This includes restart_policy, replicas, resources, and more. Your Docker version (18.04.0-ce) fully supports this specification.

As a quick side note: For non-Swarm deployments (using docker-compose up), you’d use the simpler restart: on-failure syntax directly under the service definition. But Swarm requires the deploy.restart_policy structure with the properly formatted key name.

Once you’ve updated the file, re-run your deployment command:

docker stack deploy -c docker-compose.yml stackdemo

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 06:40:30