创建配置文件

docker容器内部:/etc/mysql/my.conf 里面配置如下:

!includedir /etc/mysql/conf.d/ !includedir /etc/mysql/mysql.conf.d/ 这里包含了一个默认配置,如下:mysqld.cnf

  1. [mysqld]
  2. pid-file = /var/run/mysqld/mysqld.pid
  3. socket = /var/run/mysqld/mysqld.sock
  4. datadir = /var/lib/mysql
  5. #log-error = /var/log/mysql/error.log
  6. # By default we only accept connections from localhost
  7. #bind-address = 127.0.0.1
  8. # Disabling symbolic-links is recommended to prevent assorted security risks
  9. symbolic-links=0

所以,我们可以在宿主机内部 /data/mysql/conf.d 创建配置文件 my.cnf

创建容器

  1. docker run -di \
  2. --name mysql \
  3. -p 3306:3306 \
  4. -v /data/mysql/data:/var/lib/mysql \
  5. -v /data/mysql/conf.d:/etc/mysql/conf.d \
  6. -e MYSQL_ROOT_PASSWORD=123456 \
  7. mysql:5.7.23