ERROR: In file './docker-compose.yml', volume must be a mapping not a string

后端 未结 8 1814
清歌不尽
清歌不尽 2020-12-09 02:31

Question: Why do I get this error?

ERROR: In file \'./docker-compose.yml\', volume \'mariavolume\' must be a mapping not a string.

8条回答
  •  北海茫月
    2020-12-09 03:18

    I've just tackled this issue myself. If you just want a volume to store data, then do as below. This will create/reuse a volume that is persisted to disk as part of the Docker graph driver.

    The next question is where is this?.

    You can find it inside the docker image - Default Location -

    C:\Users\Public\Documents\Hyper-V\Virtual hard disks

    db:
      image: mariadb
      restart: always
      environment:
        MYSQL_ROOT_PASSWORD: example
      volumes:
        - maria_volume: /var/lib/mysql
    
    volumes:
      maria_volume:
    

    Of course, if you are after mapping a host directory into docker rather than having it inside the Docker graph driver. Then you can do it as follows.

    db:
      image: mariadb
      restart: always
      environment:
        MYSQL_ROOT_PASSWORD: example
      volumes:
        - maria_volume: /var/lib/mysql
    
    volumes:
      maria_volume:
        driver: local
        driver_opts:
          o: bind
          type: none
          device: /C/mariadb
    

    Please note, when mapping over host directories as volume (at least on windows) you can have issues with read/write permissions, something I have yet to resolve myself.

提交回复
热议问题