Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Question: Why do I get this error?

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

My docker-compose file is almost identical to this one: https://docs.docker.com/compose/wordpress/

version: '2' services:   wordpress:     image: wordpress:latest     restart: always     depends_on:       - db     ports:       - 8080:80     environment:       WORDPRESS_DB_PASSWORD: example       WORDPRESS_DB_HOST: 3306   db:     image: mariadb     restart: always     environment:       MYSQL_ROOT_PASSWORD: example     volumes:       - maria_volume: /var/lib/mysql volumes:   maria_volume: ~/mariadb 
like image 498
Richard Avatar asked Dec 26 '16 17:12

Richard


2 Answers

In my case this was happening because I missed adding a : after the volume name.

Instead of:

volumes:     - mysqldata: 

I had typed:

volumes:     - mysqldata 

docker-compose up gave me the same error as above.

like image 107
Dhiraj Gupta Avatar answered Sep 28 '22 08:09

Dhiraj Gupta


Unfortunately, there is no such a feature.

You can’t map a top-level volume in docker-compose.

Here are the options:

  • Adding volume per container and map it there. (like what Daniel did here)
  • Create a volume outside of the compose (with mapping) and use it in your compose.

    volumes:    maria_volume:         external:            name: volume-name 
like image 36
DaNeSh Avatar answered Sep 28 '22 06:09

DaNeSh