如果运行$ docker-compose down
以下命令,我似乎无法使MySQL数据持久化.yml
version: '2'
services:
# other services
data:
container_name: flask_data
image: mysql:latest
volumes:
- /var/lib/mysql
command: "true"
mysql:
container_name: flask_mysql
restart: always
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: 'test_pass' # TODO: Change this
MYSQL_USER: 'test'
MYSQL_PASS: 'pass'
volumes_from:
- data
ports:
- "3306:3306"
我的理解是,在我的data
容器中,使用volumes: - /var/lib/mysql
将其映射到我的本地计算机目录,在该目录中mysql将数据存储到容器中,由于这种映射,即使容器被破坏,数据也应持久存在。并且mysql
容器只是进入db的客户端接口,并且可以看到本地目录,因为volumes_from: - data
尝试此答案,但没有用。Docker组成的持久性数据故障
编辑
改变了我.yml
如下图所示,并创造了该目录./data
,但现在当我运行docker-compose up --build
的mysql
容器不会开始抛出错误说
data:
container_name: flask_data
image: mysql:latest
volumes:
- ./data:/var/lib/mysql
command: "true"
mysql:
container_name: flask_mysql
restart: always
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: 'test_pass' # TODO: Change this
MYSQL_USER: 'test'
MYSQL_PASS: 'pass'
volumes_from:
- data
ports:
- "3306:3306"
flask_mysql | mysqld: Can't create/write to file '/var/lib/mysql/is_writable' (Errcode: 13 - Permission denied)
flask_mysql | 2016-08-26T22:29:21.182144Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
flask_mysql | 2016-08-26T22:29:21.185392Z 0 [ERROR] --initialize specified but the data directory exists and is not writable. Aborting.