ERROR: In file './docker-compose.yml', vol

2019-01-24 10:15发布

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

6条回答
时光不老,我们不散
2楼-- · 2019-01-24 10:44

try this:

    volumes:
        - maria_volume: /var/lib/mysql
volumes:
    maria_volume: 
        external:
            name: ~/mariadb
查看更多
Bombasti
3楼-- · 2019-01-24 10:49

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.

查看更多
兄弟一词,经得起流年.
4楼-- · 2019-01-24 10:51

For me this works:

In #docker_compose.yml:

volumes:
  postgres_data: {}
  static: { }
查看更多
Luminary・发光体
5楼-- · 2019-01-24 10:54

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
    
查看更多
再贱就再见
6楼-- · 2019-01-24 10:55

Try this:

version: '2'
services:
  ...
  db:
    image: mariadb
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example
    volumes:
      - ~/mariadb:/var/lib/mysql
查看更多
我欲成王,谁敢阻挡
7楼-- · 2019-01-24 10:56

I was running into the same issue as yourself and as a last act of despair I tried putting

volumes:
  - maria_volume: /var/lib/mysql

before

environment:
  MYSQL_ROOT_PASSWORD: example

I'm not sure what kind of magic applied here but in my case, it worked

Let me know!

查看更多
登录 后发表回答