基础镜像基于Centos,因此体积较大,可以在测试环境快速部署,Mariadb为二进制安装
也可以直接访问github查看:https://github.com/LinuxEA-Mark/docker-mariaDB
一键安装Mariadb:
curl -LKs4 https://raw.githubusercontent.com/LinuxEA-Mark/docker-mariaDB/master/docker-mysql-create.sh|bash
一键安装Docker&compose:
curl -Lks https://get.docker.com/ | sh
curl -LkO https://github.com/xiaoyawl/docker-shadowsocks_r/raw/master/docker-compose.yml
docker-compose up -d
这里需要注意是容器内的数据目录位置和挂载点位置,my.conf中的datadir位置和日志
datadir=/data/mysql/
log_error = /data/logs/mysql/mysql-error.log
其次,在启动第一次是否进行初始化
#!/bin/bash
# if the /data/data directory doesn't contain anything, then initialise it
directory="/data/mysql"
if [ "$(ls -A $directory)" ]; then
/usr/local/mysql/bin/mysqld_safe
else
/usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/data/mysql/ --basedir=/usr/local/mysql
/usr/local/mysql/bin/mysqld --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql --init-file=/initialization.sql
fi
还有初次初始化
DELETE FROM mysql.user WHERE User='';
DELETE FROM mysql.db WHERE Db LIKE 'test%';
DROP DATABASE test;
UPDATE mysql.user SET password = password('abc123') WHERE user = 'root';
CREATE DATABASE jumpserver charset='utf8';
GRANT ALL PRIVILEGES ON jumpserver.* To 'jumpserver'@'%' IDENTIFIED BY 'password';
flush privileges;