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

Docker卷必须为映射而非字符串错误排查(附docker-compose配置)

Fixing "Docker volume must be a mapping, not a string" Error in Your WordPress Docker Compose

Let's break down what's causing this error and fix your docker-compose.yaml step by step:

1. The Root Cause of the Volume Error

The error message points directly to the last line of your file: volumes:... — this is invalid YAML syntax for defining volumes. When using named volumes (like your db_data), you need to explicitly declare them in the top-level volumes section, even if you don't add any extra configuration for them.

2. Critical Typos Breaking File Parsing

You've got two typos that are throwing off Docker Compose's ability to read the file correctly (which can also contribute to confusing error messages):

  • serivces → should be services (missing the letter 'c')
  • evironment (under the db service) → should be environment (missing the letter 'n')

Corrected docker-compose.yaml File

Here's the fully fixed version of your Compose file:

version: '3.3'
services:
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - "8000:80"
    volumes:
      - ./:/var/www/html
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
volumes:
  db_data:

Key Fixes Explained:

  • Valid Volume Declaration: Replaced volumes:... with volumes: db_data: — this tells Docker to create and manage the persistent db_data volume for MySQL.
  • Fixed Service Key: services is the correct top-level key for defining your containers, so Docker can now properly read your db and wordpress service configurations.
  • Fixed Environment Key: Correcting evironment to environment ensures the database's password and connection settings are applied properly.

After updating your file, run docker-compose up -d again — this should resolve the volume error and start your WordPress and MySQL containers successfully.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 07:21:54