英文:
docker-compose - service 'volumes' must be a mapping not an array
问题
在您将此问题标记为重复之前,请注意我已经查看了很多帖子,但没有一个能解决问题。
以下是我的Docker Compose文件:
version: '3'
services:
  # nginx
  nginx:
    build: ./nginx
    volumes:
      - ./site:/var/www/html
    ports:
      - '8080:80'
    depends_on:
      - php
  # database
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: bedrock123
      MYSQL_DATABASE: xyz
      MYSQL_USER: iamuser
      MYSQL_PASSWORD: iampass
    networks:
      - wpsite
      
  # php
  php:
    image: php:latest
    volumes:
      - ./site:/var/www/html
我意识到可能存在缩进错误,但我已经检查过了,但似乎并没有解决问题。
英文:
before you mark this question as duplicate, I have looked in a lot of threads and none of them are solving the problem.
here is my docker compose file:
version: '3'
services:
  # nginx
  nginx:
    build : ./nginx
    volumes: 
      - ./site:/var/www/html
    ports:
      - '8080:80'
    depends_on:
      php
  # database
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: bedrock123
      MYSQL_DATABASE: xyz
      MYSQL_USER: iamuser
      MYSQL_PASSWORD: iampass
    networks:
      - wpsite
  
  # php
  php:
    image: php:latest
  volumes:
    - ./site:./var/www/html
I am aware of probable indentation faults, and I did check for them but that doesn't seem to solve the problem.
答案1
得分: 10
这是一个缩进问题。php容器的卷需要缩进。否则,卷会被视为另一个要运行的服务。
php
php:
image: php:latest
volumes:
- ./site:./var/www/html
英文:
It's an indentation problem. Volumes of the php container need to be indented. Otherwise, volumes is treated as another service to run.
  # php
  php:
    image: php:latest
    volumes:
      - ./site:./var/www/html
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论