Docker - 构造持久数据故障 [英] Docker-Compose Persistent Data Trouble
问题描述
我在使用 Mariadb
配置持久性数据时遇到困难。
我使用 docker-compose
,每个服务都在一个容器中( Nginx
, PHP-FPM
和 Mariadb
)。
一切都正常,除了 Mariadb
不存储数据。每次重新启动容器时,都会丢失所有数据。然后我发现我可以使用另一个容器来保存数据,甚至不需要运行。
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.
所以我正在使用 Mariadb
容器 volume_from
内容容器。但是当我这样做时,当我尝试映射卷$ / var / lib / mysql
时,容器 MariaDb
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.
错误
2015 -12-29 12:16:40 7f2f02e4a780
InnoDB:文件操作中的操作系统错误号13。
InnoDB:错误意味着mysqld没有访问权限到
InnoDB:目录。
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.
错误是指卷权限的问题, ve尝试通过两个容器中的 Dockerfile
设置权限,并且问题仍然存在。我有点迷失了我使用的是OSX,所以我相信这是一个OSX的问题。有人可以帮助我吗?
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?
这是我的代码:
我的Docker Compose
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
内容Dockerfile
FROM debian:jessie
VOLUME /var/lib/mysql
CMD ["true"]
推荐答案
我的方式是使用busybox来存储和共享mariadb的所有数据。然后在mariadb中使用 - 卷从
链接该目录。请查看我简单的 compose.yml
文件。
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.
docker-compose 2.0的更新
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
您可以通过运行命令查看docker在该硬盘上的存储位置:
docker volume inspect docker_database
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 - 构造持久数据故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!