docker容器中的mysql无法在os x上运行已安装的卷

在OS X上.

我试图通过boot2docker在docker容器中运行mysql,通过在主机上挂载volume / var / lib / mysql,这样我就可以拥有持久的mysql数据.
我计划将来使用仅数据容器,但是现在我正在尝试使用此选项.

我使用以下命令来运行容器:

docker run -v / Users / yash / summers / db:/ var / lib / mysql -i -t’image name’

/ Users / yash / summers / db文件夹已经存在.

我正面临着这方面的问题.使用命令行,我能够访问目录,创建/删除新文件,但是当我运行时
服务mysql启动,我收到以下错误:

150528 15:43:43 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
150528 15:43:43 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
150528 15:43:43 [Note] /usr/sbin/mysqld (mysqld 5.5.43-0ubuntu0.14.04.1) starting as process 909 ... 
150528 15:43:43 [Warning] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
150528 15:43:43 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.150528 15:43:43 [Note] Plugin 'FEDERATED' is disabled.
/usr/sbin/mysqld: Table 'mysql.plugin' doesn't exist
150528 15:43:43 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
150528 15:43:43 InnoDB: The InnoDB memory heap is disabled
150528 15:43:43 InnoDB: Mutexes and rw_locks use GCC atomic builtins
150528 15:43:43 InnoDB: Compressed tables use zlib 1.2.8 
150528 15:43:43 InnoDB: Using Linux native AIO
150528 15:43:43 InnoDB: Initializing buffer pool,size = 128.0M
150528 15:43:43 InnoDB: Completed initialization of buffer pool
150528 15:43:43  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.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'create'.
InnoDB: Cannot continue operation.
150528 15:43:44 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended 

在过去的两天里,我试图解决这个问题,经历了很多页面,如this,thisthis.

我无法解决我的问题.我想我无法完美地完成解决方案的建议.

根据我的理解,这些页面上列出了一些解决方法,包括更改uid和guid,但我认为它们没有得到很好的解释.

任何人都可以向我解释一个详细的解决方法.

更新1:我尝试使用仅数据容器,仍然面临同样的问题.

如果我不使用任何-v或–volumes-from选项,我可以运行一切正常,所以我认为在mysql服务器中没有问题.

更新2:
用于创建仅数据容器的Dockerfile:

FROM ubuntu

RUN mkdir /var/lib/mysql

VOLUME /var/lib/mysql
最佳答案
有两种不同的解决方案.

>解决方案#1.使用Dockerfile

(我不喜欢它因为我更喜欢Docker Hub中的官方图像而没有任何更改)

将RUN usermod -u 1000 mysql添加到Docker文件中以设置ID 1000
对于用户“mysql”(与docker-machine内部相同的ID).
>解决方案#2.用my.cnf.

我仍然使用自己的配置我更喜欢这个解决方案.我们alredy拥有ID为1000的root用户,因为我们
可以用这个用户运行MySQL:

> my.cnf

主行是user = root(你可以使用sed只更改文件中的这一行.我更喜欢mount all file)

[client]
port        = 3306
socket      = /var/run/mysqld/mysqld.sock
default-character-set = utf8

[mysqld_safe]
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
nice        = 0

[mysqld]
user        = root
pid-file    = /var/run/mysqld/mysqld.pid
socket      = /var/run/mysqld/mysqld.sock
port        = 3306
basedir     = /usr
datadir     = /var/lib/mysql
tmpdir      = /tmp
lc-messages-dir = /usr/share/mysql
explicit_defaults_for_timestamp
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address   = 127.0.0.1

#log-error  = /var/log/mysql/error.log

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf',otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/

>使用此文件更改默认my.cnf:

docker run -it -v ./mysql/var/lib/mysql:/var/lib/mysql -v ./my.cnf::/etc/mysql/my.cnf mariadb:10.0.22

相关文章

最近一直在开发Apworks框架的案例代码,同时也在一起修复Apw...
最近每天都在空闲时间努力编写Apworks框架的案例代码WeText。...
在《Kubernetes中分布式存储Rook-Ceph部署快速演练》文章中,...
最近在项目中有涉及到Kubernetes的分布式存储部分的内容,也...
CentOS下Docker与.netcore(一) 之 安装 CentOS下Docker与.ne...
CentOS下Docker与.netcore(一) 之 安装 CentOS下Docker与.ne...