startup.sh
#!/bin/bash
docker build -t mysql .
docker run --name mysql8.0 --privileged=true -v /Users/xingyue/Home/xingyue/mysql8.0/conf:/etc/mysql/my.conf -v /Users/xingyue/Home/xingyue/mysql8.0/logs:/logs -v /Users/xingyue/Home/xingyue/mysql8.0/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -p 3308:3306 -d mysql:8.0
privileges.sql
use xxx_databases;
ALTER user 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'Swj@5201314';
FLUSH PRIVILEGES;
Dockerfile
FROM mysql:8
MAINTAINER xingyue
COPY privileges.sql /privileges.sql
# 把要执行的shell文件放到/docker-entrypoint-initdb.d/目录下,容器会自动执行这个shell
COPY startup.sh /docker-entrypoint-initdb.d/startup.sh
# 给执行文件增加可执行权限
RUN chmod a+x /docker-entrypoint-initdb.d/startup.sh