Docker-Compose 持久数据问题 [英] Docker-Compose Persistent Data Trouble
问题描述
我在使用 Mariadb
配置持久数据时遇到问题.我正在使用 docker-compose
,每个服务都在一个容器中(Nginx
、PHP-FPM
和 Mariadb
).一切正常,除了 Mariadb
不存储数据.每次我重新启动容器时,我都会丢失所有数据.然后我发现我可以使用另一个容器来保存数据,它甚至不必运行.
所以我在 Mariadb
容器中使用 volume_from
内容容器.但是当我这样做时,当我尝试映射卷 /var/lib/mysql
时,容器 MariaDb
不会启动.
错误
<块引用>2015-12-29 12:16:40 7f2f02e4a780
InnoDB:文件操作中的操作系统错误号 13.
InnoDB:错误表示mysqld没有访问权限
InnoDB:目录.
错误是指卷权限的问题,但我尝试在两个容器中通过Dockerfile
设置权限,问题依然存在.我有点失落.我正在使用 OSX,所以我相信这是一个 OSX 问题.谁能帮我解决这个问题?
这是我的代码:
我的 Docker 撰写
<上一页>内容:构建:容器/内容容器名称:内容主机名:内容卷:-/var/lib/mysql玛丽亚数据库:构建:容器/mariadb容器名称:mariadb主机名:mariadb端口:- 3306:3306"卷_来自:- 内容环境:- MYSQL_ROOT_PASSWORD=mariadb- 期限=xterm- 端口=3306MariaDB Dockerfile
内容 Dockerfile
我这样做的方式是使用busybox来存储所有数据并与mariadb共享.然后使用 mariadb 中的 --volumes-from
链接该目录.请查看我的简化 compose.yml
文件.
数据库数据:容器名称:数据库数据图片:busybox:最新卷:-/data/mysql:/var/lib/mysqlD b:容器名称:分贝图片:百万12/mariadb重启:总是卷_来自:- 数据库数据环境:- MARIADB_USER=管理员- MARIADB_PASS=my_pass
现在所有数据库文件都可以在主机操作系统上访问,并且不应该有任何权限问题.
docker-compose 2.0 更新
版本:'2'卷:数据库:服务:D b:容器名称:分贝图片:百万12/mariadb重启:总是卷_来自:- 数据库环境:- MARIADB_USER=管理员- MARIADB_PASS=my_pass
您可以通过运行以下命令查看 docker 在硬盘上存储该卷的位置:docker 卷检查 docker_database
<代码>[{"名称": "docker_database",驱动程序":本地",挂载点":/var/lib/docker/volumes/docker_database/_data",标签":空,范围":本地"}
]
I'm having trouble in configuring persistent data with Mariadb
.
I'm using docker-compose
, with each service in a single container (Nginx
, PHP-FPM
and Mariadb
).
Everything is working, except Mariadb
doesn't store data. Every time I restart the container, I lose all the data. Then I found out that I can use another container just to keep data, and it doesn't even have to be running.
So I'm using, in Mariadb
container volume_from
content container. But when I do that, when I try to map the volume /var/lib/mysql
, the Container MariaDb
doesn't start.
Error
2015-12-29 12:16:40 7f2f02e4a780
InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
The error refers to a problem about volume permissions, but I've tried to set permissions through Dockerfile
in both containers, and the problem persists. I'm a bit lost. I'm using OSX, so I believe this is an OSX problem. Can anyone help me on this?
This is my code:
My Docker Compose
content: build: containers/content container_name: content hostname: content volumes: - /var/lib/mysql mariadb: build: containers/mariadb container_name: mariadb hostname: mariadb ports: - "3306:3306" volumes_from: - content environment: - MYSQL_ROOT_PASSWORD=mariadb - TERM=xterm - PORT=3306
MariaDB Dockerfile
FROM debian:jessie RUN apt-get update && apt-get install -y mariadb-server EXPOSE 3306
Content Dockerfile
FROM debian:jessie VOLUME /var/lib/mysql CMD ["true"]
The way i do it is that I use busybox for all data stored and shared with mariadb. Then use --volumes-from
in mariadb to link that directories. Please have a look into my simpified compose.yml
file.
db-data:
container_name: db-data
image: busybox:latest
volumes:
- /data/mysql:/var/lib/mysql
db:
container_name: db
image: million12/mariadb
restart: always
volumes_from:
- db-data
environment:
- MARIADB_USER=admin
- MARIADB_PASS=my_pass
Now all database files are accessible on host os too and there shouldn't be any permissions issues.
Update for docker-compose 2.0
version: '2'
volumes:
database:
services:
db:
container_name: db
image: million12/mariadb
restart: always
volumes_from:
- database
environment:
- MARIADB_USER=admin
- MARIADB_PASS=my_pass
You can see where docker is storing that volume on your hard drive by running command:
docker volume inspect docker_database
[
{
"Name": "docker_database",
"Driver": "local",
"Mountpoint": "/var/lib/docker/volumes/docker_database/_data",
"Labels": null,
"Scope": "local"
}
]
这篇关于Docker-Compose 持久数据问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!