/var/lib/mysql/is_writable,Docker - 编写永久数据MySQL

I can't seem to get MySQL data to persist if I run $ docker-compose down with the following .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"

My understanding is that in my data container using volumes: - /var/lib/mysql maps it to my local machines directory where mysql stores data to the container and because of this mapping the data should persist even if the containers are destroyed. And the mysql container is just a client interface into the db and can see the local directory because of volumes_from: - data

Attempted this answer and it did not work. Docker-Compose Persistent Data Trouble

EDIT

Changed my .yml as shown below and created a the dir ./data but now when I run docker-compose up --build the mysql container wont start throws error saying

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.

解决方案

The data container is an superfluous workaround. Data-volumes would do the trick for you. Alter your docker-compose.yml to:

version: '2'

services:

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:

- my-datavolume:/var/lib/mysql

volumes:

my-datavolume:

Docker will create the volume for you in the /var/lib/docker/volumes folder. This volume persist as long as you are not typing docker-compose down -v

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值