我在OSX上使用mariadb遇到了麻烦,我在CentOS上做了同样的事情并且工作正常。所以它必须是OSX问题:
mariadb:
image: mariadb:latest
container_name: mariadb
ports:
- "3306:3306"
restart: always
environment:
MYSQL_ROOT_PASSWORD: XXXXXXXX
volumes:
- /Users/sandro/Code/mysql:/var/lib/mysql
日志包含以下错误:
mkdir: cannot create directory '/var/lib/mysql//mysql': Permission denied
Fatal error Can't create database directory '/var/lib/mysql//mysql'
如果我让它像这样安装在容器内:
volumes:
- /var/lib/mysql
它有效,但我有持久性问题,一旦vm重新启动,dbs就会消失。
我尝试创建mysql目录并为其提供全局可写权限,并收到以下错误:
2016-05-20 23:43:54 140694234605504 [Note] mysqld (mysqld 10.1.14-MariaDB-1~jessie) starting as process 1 ...
2016-05-20 23:43:54 140694234605504 [Warning] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
2016-05-20 23:43:54 140694234605504 [Note] InnoDB: Using mutexes to ref count buffer pool pages
2016-05-20 23:43:54 140694234605504 [Note] InnoDB: The InnoDB memory heap is disabled
2016-05-20 23:43:54 140694234605504 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-05-20 23:43:54 140694234605504 [Note] InnoDB: Memory barrier is not used
2016-05-20 23:43:54 140694234605504 [Note] InnoDB: Compressed tables use zlib 1.2.8
2016-05-20 23:43:54 140694234605504 [Note] InnoDB: Using Linux native AIO
2016-05-20 23:43:54 140694234605504 [Note] InnoDB: Using SSE crc32 instructions
2016-05-20 23:43:54 140694234605504 [Note] InnoDB: Initializing buffer pool, size = 256.0M
2016-05-20 23:43:54 140694234605504 [Note] InnoDB: Completed initialization of buffer pool
2016-05-20 23:43:54 140694234605504 [ERROR] InnoDB: ./ibdata1 can't be opened in read-write mode
2016-05-20 23:43:54 140694234605504 [ERROR] InnoDB: The system tablespace must be writable!
2016-05-20 23:43:54 140694234605504 [ERROR] Plugin 'InnoDB' init function returned error.
2016-05-20 23:43:54 140694234605504 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2016-05-20 23:43:54 140694234605504 [ERROR] mysqld: File '/var/lib/mysql/aria_log_control' not found (Errcode: 13 "Permission denied")
2016-05-20 23:43:54 140694234605504 [ERROR] mysqld: Got error 'Can't open file' when trying to use aria control file '/var/lib/mysql/aria_log_control'
2016-05-20 23:43:54 140694234605504 [ERROR] Plugin 'Aria' init function returned error.
2016-05-20 23:43:54 140694234605504 [ERROR] Plugin 'Aria' registration as a STORAGE ENGINE failed.
2016-05-20 23:43:54 140694234605504 [Note] Plugin 'FEEDBACK' is disabled.
2016-05-20 23:43:54 140694234605504 [ERROR] Could not open mysql.plugin table. Some plugins may be not loaded
2016-05-20 23:43:54 140694234605504 [ERROR] Unknown/unsupported storage engine: InnoDB
2016-05-20 23:43:54 140694234605504 [ERROR] Aborting
答案 0 :(得分:2)
使mysql容器以用户1000的身份运行。
在Dockerfile中:
USER "1000"
在docker-compose.yml
中db:
image: mysql
user: "1000"
这是我当前的解决方法(通过docker-compose.yml完成)。 1000用户是 - 我相信 - docker卷中文件的默认用户(至少对于docker-machine),所以这应该让你写入卷。
答案 1 :(得分:1)
很可能是它的许可问题。在Mac上,docker在虚拟框中运行,通过VM映射本地目录。获得权限是很棘手的。首先尝试在/ Users / sandro / Code目录上设置限制最少的权限。还要尝试预先创建/ Users / sandro / Code / myssql目录,并在启动容器之前为其提供全局可写权限。
更新:所以问题实际上更复杂。看起来你不能做很多低级文件调用,除非容器内的用户id与启动docker机器的用户的id匹配。以下是一些澄清此问题的链接:
https://github.com/boot2docker/boot2docker/issues/581
问题出在boot2docker,MariaDB图像启动脚本,docker-compose和Virtual Box客户操作系统之间
我能够通过这样做运行maria db容器
mkdir mysql
chmod ug+ws mysql
docker run -it -u $UID:$UID -e MYSQL_ROOT_PASSWORD=bob \
-v /Users/vlad/Proj/Stack/maria/mysql:/var/lib/mysql \
mariadb:latest
请注意-u选项
答案 2 :(得分:0)
错误消息中的路径看起来很奇怪:
mkdir: cannot create directory '/var/lib/mysql//mysql': Permission denied
对我来说,看起来mariadb图像是在卷路径上追加/ mysql。通过删除docker-compose.yml文件中的/mysql
,它就像魅力一样。
mdb:
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: password
volumes:
- ./data:/var/lib