wordpress 错误:在文件“./docker-compose.yml”中,卷必须是映射而不是字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41334488/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ERROR: In file './docker-compose.yml', volume must be a mapping not a string
提问by Richard
Question:Why do I get this error?
问题:为什么会出现此错误?
ERROR: In file './docker-compose.yml', volume 'mariavolume' must be a mapping not a string.
错误:在文件“./docker-compose.yml”中,卷“mariavolume”必须是映射而不是字符串。
My docker-compose file is almost identical to this one: https://docs.docker.com/compose/wordpress/
我的 docker-compose 文件几乎与这个相同: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
回答by Dhiraj Gupta
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.
docker-compose up
给了我与上面相同的错误。
回答by DaNeSh
Unfortunately, there is no such a feature.
不幸的是,没有这样的功能。
You can't map a top-level volume in docker-compose.
您无法在 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
- 添加每个容器的卷并将其映射到那里。(就像丹尼尔在这里所做的那样)
在撰写之外创建一个卷(带映射)并在你的撰写中使用它。
volumes: maria_volume: external: name: volume-name
回答by JonWillis
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.
我刚刚自己解决了这个问题。如果您只是想要一个卷来存储数据,请执行以下操作。这将创建/重用volume
作为Docker
图形驱动程序的一部分持久保存到磁盘的。
The next question is where is this?.
下一个问题是这是哪里?.
You can find it inside the docker image - Default Location -
您可以在 docker 镜像中找到它 - 默认位置 -
C:\Users\Public\Documents\Hyper-V\Virtual hard disks
C:\Users\Public\Documents\Hyper-V\虚拟硬盘
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.
当然,如果您将主机目录映射到 docker 而不是将它放在Docker
图形驱动程序中。然后你可以按如下方式进行。
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.
请注意,将主机目录映射为卷(至少在 Windows 上)时,您可能会遇到read/write
权限问题,这是我自己尚未解决的问题。
回答by Mohsen ZareZardeyni
try this:
尝试这个:
volumes:
- maria_volume: /var/lib/mysql
volumes:
maria_volume:
external:
name: ~/mariadb
回答by Akshay Vijay Jain
correct syntax for volume isvolumes:
first:
where first is just a placeholder name to be used for volume
卷的正确语法是volumes:
first:
first 只是用于卷的占位符名称
回答by kinjelom
Try this:
尝试这个:
version: '2'
services:
...
db:
image: mariadb
restart: always
environment:
MYSQL_ROOT_PASSWORD: example
volumes:
- ~/mariadb:/var/lib/mysql
回答by Daniel
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!
让我知道!
回答by Deepak Sharma
For me this works:
对我来说这有效:
In #docker_compose.yml:
在#docker_compose.yml 中:
volumes:
postgres_data: {}
static: { }