Tag Archives: Docker compose error

[Solved] Docker compose error: ERROR: Encountered errors while bringing up the project.

Error running docker compose file:

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 original file

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"

The problem description shows that the path is wrong. After careful inspection, it is found that the data volume data: var/lib/MySQL is missing /, which should be:

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