Docker与MySQL:错误意味着mysqld没有目录的访问权限

我在Mac 10.11.3 (15D21)

关于Docker我有:

 $ docker version Client: Version: 1.10.3 API version: 1.22 Go version: go1.5.3 Git commit: 20f81dd Built: Thu Mar 10 21:49:11 2016 OS/Arch: darwin/amd64 Server: Version: 1.10.3 API version: 1.22 Go version: go1.5.3 Git commit: 20f81dd Built: Thu Mar 10 21:49:11 2016 OS/Arch: linux/amd64 

对于Mysql

 $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE mysql latest 7a5866c2edbf 12 days ago 361.3 MB ... 

我做了以下几点:

  • mkdir -p /Users/me/docker/mysql/data
  • chmod -R 777 /Users/me/docker/mysql/data

(即使每个命令使用sudo)

它来自Pro Docker和: 在OSX中安装Docker卷时拒绝许可

即使这样做:

  • docker -v /Users/me/docker/mysql/data:/var/lib/mysql mysql chown -R mysql /var/lib/mysql

它来自: 数据库无法启动 – 主机目录作为数据卷

当我执行:(显示多行以更好的可视化)

 docker run -v /Users/me/docker/mysql/data:/var/lib/mysql --name manolitomysql -e MYSQL_DATABASE='mysqldb' -e MYSQL_USER='mysql' -e MYSQL_PASSWORD='mysql' -e MYSQL_ALLOW_EMPTY_PASSWORD='yes' -e MYSQL_ROOT_PASSWORD='' -d mysql 

我总是得到:

 $ docker logs manolitomysql Initializing database 2016-03-27T16:04:33.520170Z 0 [Warning] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive 2016-03-27T16:04:35.089907Z 0 [ERROR] InnoDB: Operating system error number 13 in a file operation. 2016-03-27T16:04:35.090006Z 0 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory. 2016-03-27 16:04:35 0x7f061a050740 InnoDB: Assertion failure in thread 139664183068480 in file fil0fil.cc line 868 InnoDB: Failing assertion: success InnoDB: We intentionally generate a memory trap. InnoDB: Submit a detailed bug report to http://bugs.mysql.com. InnoDB: If you get repeated assertion failures or crashes, even InnoDB: immediately after the mysqld startup, there may be InnoDB: corruption in the InnoDB tablespace. Please refer to InnoDB: http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html InnoDB: about forcing recovery. 16:04:35 UTC - mysqld got signal 6 ; This could be because you hit a bug. It is also possible that this binary or one of the libraries it was linked against is corrupt, improperly built, or misconfigured. This error can also be caused by malfunctioning hardware. Attempting to collect some information that could help diagnose the problem. As this is a crash and something is definitely wrong, the information collection process might fail. key_buffer_size=8388608 read_buffer_size=131072 max_used_connections=0 max_threads=151 thread_count=0 connection_count=0 It is possible that mysqld could use up to key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 68188 K bytes of memory Hope that's ok; if not, decrease some variables in the equation. Thread pointer: 0x0 Attempting backtrace. You can use the following information to find out where mysqld died. If you see no messages after this, something went terribly wrong... stack_bottom = 0 thread_stack 0x40000 mysqld(my_print_stacktrace+0x2c)[0xe57c7c] mysqld(handle_fatal_signal+0x459)[0x7896b9] /lib/x86_64-linux-gnu/libpthread.so.0(+0xf8d0)[0x7f0619c2d8d0] /lib/x86_64-linux-gnu/libc.so.6(gsignal+0x37)[0x7f061841b067] /lib/x86_64-linux-gnu/libc.so.6(abort+0x148)[0x7f061841c448] mysqld[0x75fc29] mysqld[0x1180f68] mysqld(_Z40fil_open_log_and_system_tablespace_filesv+0xe4)[0x1185a74] mysqld[0x107afe0] mysqld(_Z34innobase_start_or_create_for_mysqlv+0x3692)[0x107eb12] mysqld[0xf4a05d] mysqld(_Z24ha_initialize_handlertonP13st_plugin_int+0x51)[0x7d3981] mysqld[0xc53716] mysqld(_Z11plugin_initPiPPci+0x5c8)[0xc5a5c8] mysqld[0x782164] mysqld(_Z11mysqld_mainiPPc+0x7b2)[0x7835d2] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5)[0x7f0618407b45] mysqld[0x77a274] The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains information that should help you find out what is causing the crash. 

需要额外的configuration吗?

根据以下说明,使用Dockerfile可能会更好地进行控制:

 RUN useradd mysql RUN mkdir /var/lib/mysql && chown -R mysql:mysql /var/lib/mysql 

对于观众来说,以下作品:

1使用创build一个Dockerfile

 FROM mysql:latest RUN deluser mysql RUN useradd mysql RUN mkdir -p /Users/me/docker/mysql/data RUN chmod -R 777 /Users/me/docker/mysql/data 

2使用以前的Dockerfile创build一个新的图像

3使用上一张图像运行新容器