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

前端之家收集整理的这篇文章主要介绍了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

原文链接:https://www.f2er.com/docker/436894.html

猜你在找的Docker相关文章