docker-compose报错解决

运行docker-compose文件出错:

ERROR: for yingxue_mysql_1  Cannot create container for service mysql: invalid volume specification: 'yingxue_data:var/lib/mysql:rw': invalid mount config for type "volume": invalid mount path: 'var/lib/mysql' mount path must be absolute

ERROR: for mysql  Cannot create container for service mysql: invalid volume specification: 'yingxue_data:var/lib/mysql:rw': invalid mount config for type "volume": invalid mount path: 'var/lib/mysql' mount path must be absolute
ERROR: Encountered errors while bringing up the project.

docker-compose原始文件

version: "3.3"

networks:
  yingxue_network:

volumes: #声明服务所使用的自动创建的卷名
  data:

services:
  nacos:
    image: nacos/nacos-server:2.0.2
    ports:
      - "8848:8848"
    environment:
      - "JVM_XMS=256m"
      - "JVM_XMX=256m"
      - "MODE=standalone"
    networks:
      - yingxue_network

  mysql:
    image: mysql:5.7
    ports:
      - "3306:3306"
    networks:
      - yingxue_network
    volumes:
      - data:var/lib/mysql
      - ./yingxue.sql:/docker-entrypoint-initdb.d/yingxue.sql
    environment:
      #怀疑是环境出错
      - "MYSQL_ROOT_PASSWORD=root"
      - "MYSQL_DATABASE=yingxue"

查看问题描述是路径不对,仔细检查后发现是数据卷data:var/lib/mysql少了个/,应该为:

    volumes:
      - data:/var/lib/mysql
      - ./yingxue.sql:/docker-entrypoint-initdb.d/yingxue.sql

你可能感兴趣的:(bug,docker)