资讯专栏INFORMATION COLUMN

Macosx 下如何使用docker/mysql

ygyooo / 2969人阅读

摘要:问题描述在下如果指定本地目录替换,运行时会出现文件权限的错误,导致无法正常运行解决方案创建在目录下启动脚本创建,指定脚本为容器入口运行命令,启动容器

问题描述

在macosx下如果指定本地目录替换/var/lib/mysql,运行时会出现文件权限的错误,导致mysqld无法正常运行

Creating mysql_test-mysql_1
Attaching to mysql_test-mysql_1
test-mysql_1 | Initializing database
test-mysql_1 | 2016-03-23T04:32:37.437789Z 0 [Warning] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
test-mysql_1 | 2016-03-23T04:32:37.466955Z 0 [ERROR] InnoDB: Operating system error number 13 in a file operation.
test-mysql_1 | 2016-03-23T04:32:37.467828Z 0 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
test-mysql_1 | 2016-03-23T04:32:37.468824Z 0 [ERROR] InnoDB: Operating system error number 13 in a file operation.
test-mysql_1 | 2016-03-23T04:32:37.468912Z 0 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
test-mysql_1 | 2016-03-23T04:32:37.470280Z 0 [ERROR] InnoDB: Cannot open datafile "./ibdata1"
test-mysql_1 | 2016-03-23T04:32:37.470309Z 0 [ERROR] InnoDB: Could not open or create the system tablespace. If you tried to add new data files to the system tablespace, and it failed here, you should now edit innodb_data_file_path in my.cnf back to what it was, and remove the new ibdata files InnoDB created in this failed attempt. InnoDB only wrote those files full of zeros, but did not yet use them in any way. But be careful: do not remove old data files which contain your precious data!
test-mysql_1 | 2016-03-23T04:32:37.470317Z 0 [ERROR] InnoDB: InnoDB Database creation was aborted with error Cannot open a file. You may need to delete the ibdata1 file before trying to start up again.
test-mysql_1 | 2016-03-23T04:32:38.073222Z 0 [ERROR] Plugin "InnoDB" init function returned error.
test-mysql_1 | 2016-03-23T04:32:38.073268Z 0 [ERROR] Plugin "InnoDB" registration as a STORAGE ENGINE failed.
test-mysql_1 | 2016-03-23T04:32:38.073283Z 0 [ERROR] Failed to initialize plugins.
test-mysql_1 | 2016-03-23T04:32:38.073289Z 0 [ERROR] Aborting
test-mysql_1 | 
mysql_test-mysql_1 exited with code 1
解决方案

创建在scripts目录下mysqld启动脚本

#!/bin/bash
# From https://github.com/docker-library/mysql/issues/99
set -e # fail on any error

echo "* Working around permission errors in Docker on Mac locally by making sure that "mysql" uses the same uid and gid as the host volume"
TARGET_UID=$(stat -c "%u" /var/lib/mysql)
echo "-- Setting mysql user to use uid "$TARGET_UID
usermod -o -u $TARGET_UID mysql || true
TARGET_GID=$(stat -c "%g" /var/lib/mysql)
echo "-- Setting mysql group to use gid "$TARGET_GID
groupmod -o -g $TARGET_GID mysql || true
echo
echo "* Starting MySQL"
chown -R mysql:root /var/run/mysqld/
/entrypoint.sh mysqld --user=mysql --console

创建docker-compose.py,指定run-mysqld.sh脚本为容器入口

test-mysql:
    image: mysql 
    ports:
        - "3306:3306"
    volumes:   
        - /localhost/mysql/data:/var/lib/mysql 
        - ./scripts/run-mysqld.sh:/run-mysqld.sh
    environment:
        - MYSQL_DATABASE=play
        - MYSQL_USER=play
        - MYSQL_PASSWORD=play
        - MYSQL_ROOT_PASSWORD=123456
    entrypoint: /run-mysqld.sh

运行docker-compose up命令,启动容器

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/26552.html

相关文章

  • PhantomJS 安装

    摘要:变量如果用户目录下存在,比如我的,则添加一行否则新建然后在添加上文在中输入如果可以看到版本号,则安装成功。 PhantomJS 安装 showImg(https://segmentfault.com/img/bVL0NY?w=408&h=252); Mac OS X && Windows 1、PhantomJS下载地址 按照系统下载对应的版本, macOS 下载: phantomjs...

    tinylcy 评论0 收藏0
  • PhantomJS 安装

    摘要:变量如果用户目录下存在,比如我的,则添加一行否则新建然后在添加上文在中输入如果可以看到版本号,则安装成功。 PhantomJS 安装 showImg(https://segmentfault.com/img/bVL0NY?w=408&h=252); Mac OS X && Windows 1、PhantomJS下载地址 按照系统下载对应的版本, macOS 下载: phantomjs...

    MockingBird 评论0 收藏0

发表评论

0条评论

ygyooo

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<