0

如果执行docker run -u 0 ***
报错是

2017-08-10 20:00:51 66 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!

如果执行

docker run -d --name mysql_test -e TZ="Asia/Shanghai" -v /etc/localtime:/etc/localtime:ro -v /etc/mysql:/etc/opt/rh/rh-mysql56/my.cnf.d -e MYSQL_ROOT_PASSWORD=abc123 -p 3306 centos/mysql-56-centos7

报错是

/usr/bin/run-mysqld: line 14: /etc/my.cnf.d/base.cnf: Permission denied

其中

/etc/mysql

被尝试加过: chown -R mysql:mysql 权限
网上的一些方法也试过,没生效,求救

试了下官方5.6.34的镜像,不使用自定义cnf文件的话是ok的;
使用-v /etc/mysql:/etc/mysql/conf.d,启动容器后是existed状态,没有报错了
docker logs显示:

Initializing database
2017-08-11 03:09:18 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-08-11 03:09:18 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-08-11 03:09:18 0 [Note] /usr/sbin/mysqld (mysqld 5.6.37-log) starting as process 36 ...
2017-08-11 03:11:04 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-08-11 03:11:04 0 [Note] mysqld (mysqld 5.6.37-log) starting as process 1 ...

3个回答

0

已采纳
  1. -u 是制定容器内部用户,没必要,默认已经指定mysql

2.我建议不要随意挂在到其他位置,在挂载其他位置的时候一定记得root方式chown

官方的entrypoint

3.可以参考
注意,请使用空文件夹存储data数据,不然可能你之前的版本问题不兼容自动生成的文件

 mysql-db:
    image: mysql:5.7
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ./data/mysql:/var/lib/mysql:rw
      - ./logs/mysql:/var/lib/mysql-logs:rw
      - ./dockerfiles/mysql/conf.d:/etc/mysql/conf.d:ro
    restart: always
    ports:
      - "3306:3306"
    environment:
        MYSQL_ROOT_PASSWORD: zhaojun
        MYSQL_DATABASE: package_v1
        MYSQL_USER: zhaojun
        MYSQL_PASSWORD: zhaojun

0

这报错信息不是都有了么?Mysql不允许使用root身份运行mysqld。

话说你都用docker了为何不用mysql的docker官方镜像,却要自己造个轮子?

0

用官方镜像试试看呢?


或者你看看那个权限报错进入container里面的/etc/mysql/目录去看看是什么权限,如果权限不对你看能不能在github上找到镜像对应的dockerfile,去改一下,然后再用.或者再套一层dockerfile

撰写答案