如果我用下面的.yml运行$ docker-compose down,我似乎不能让MySQL数据持久
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"
我的理解是,在我的数据容器中使用卷:- /var/lib/mysql将它映射到我的本地机器目录,mysql将数据存储到容器中,由于这种映射,即使容器被破坏,数据也应该持久化。mysql容器只是一个进入db的客户端接口,可以看到本地目录,因为volumes_from: - data
试着回答这个问题,但没有成功。Docker-Compose持久数据故障
EDIT
更改了我的.yml如下所示,并创建了一个dir ./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.