[英]MariaDB volume in docker-compose clears out data
I'm using the yobasystems/alpine-mariadb docker image to run an instance for a development environment.我正在使用 yobasystems/alpine-mariadb docker 映像来运行开发环境的实例。 I'm mounting the data directory for MySQL to a docker volume and this has worked in the past.我正在将 MySQL 的数据目录安装到 docker 卷上,这在过去一直有效。 Every so often I lose data but not the table structure and I cannot work out why.每隔一段时间,我就会丢失数据,但不会丢失表结构,我无法弄清楚原因。
db:
image: yobasystems/alpine-mariadb
restart: always
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=database
- MYSQL_USER=user
- MYSQL_PASSWORD=password
ports:
- "33333:3306"
volumes:
- mariadb:/var/lib/mysql
I suspect that in your case the volume is getting removed(may be via docker-compose down -v
or dockere-compose rm -v
).我怀疑在您的情况下,卷被删除(可能是通过docker-compose down -v
或dockere-compose rm -v
)。
Please specify that the volume is external using -请指定该卷是外部使用 -
volumes:
mariadb:
external: true
From docker docs - external: If set to true, specifies that this volume has been created outside of Compose.来自 docker 文档 -外部:如果设置为 true,则指定此卷是在 Compose 之外创建的。 docker-compose up does not attempt to create it, and raises an error if it doesn't exist. docker-compose up 不会尝试创建它,如果它不存在则会引发错误。
You may create the volume prior to docker-compose up
with docker volume create mariadb
您可以在docker-compose up
之前创建卷,然后使用docker volume create mariadb
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.