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

Docker Compose报错volumes must be a mapping问题求助

解决Docker Compose报错“volumes must be a mapping”

错误原因

你定义的锚点&service-volumes前多了一个破折号,导致在volumes字段引用时形成了嵌套列表结构,Docker Compose无法解析这种格式,因此抛出“volumes must be a mapping”错误。

修正方案

方案1:修正锚点定义

修改docker-compose.yml中锚点的写法,去掉锚点行的破折号,让它存储单个卷的字符串值:

version: "3.10"

x-service-volumes: &service-volumes
 ./:/app/:rw,cached

services:
  website:
    image: mama_website:latest
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - *service-volumes
    ports:
      - "8000:8000"

方案2:直接定义卷(无需锚点)

如果不需要复用卷配置,也可以直接在volumes下写卷路径,格式如下:

version: "3.10"

services:
  website:
    image: mama_website:latest
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      -./:/app/:rw,cached
    ports:
      - "8000:8000"

额外检查点

  • 确保YAML文件的缩进使用2个空格(禁止用Tab),Docker Compose对缩进格式要求严格;
  • 卷路径写法规范:./:/app/:rw,cached中本地路径与容器路径的冒号前后无需空格,当前写法是正确的。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 16:05:25