1.安装MySQL
下载mysql镜像
docker pull mysql:5.7
启动容器,如果windows装了mysql会发生端口冲突建议使用3307或其他
docker run -p 3307:3306 --name mysql
-v /mydata/mysql/log:/var/log/mysql
-v /mydata/mysql/data:/var/lib/mysql
-v /mydata/mysql/conf:/etc/mysql
-e MYSQL_ROOT_PASSWORD=root
-d mysql:5.7
修改配置文件,将字符编码改为utf8
vi /mydata/mysql/conf/my.cnf
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
init_connect='SET collation connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve
重启
docker restart mysql
进入mysql容器
docker exec -it mysql /bin/bash
查看是否修改成功
cat /etc/mysql/my.cnf
退出
exit;
2.Docker安装Redis
下载redis
docker pull redis
创建配置文件
mkdir -p /mydata/redis/conf
touch /mydata/redis/conf/redis.conf
启动容器
docker run -p 6379:6379 --name redis
-v /mydata/redis/data:/data
-v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf
-d redis redis-server /etc/redis/redis.conf
运行 redis
docker exec -it redis redis-cli
开启 aof 持久化,否则容器重启以后之前存入的数据又没了
vi /mydata/redis/conf/redis.conf
# 添加如下内容
appendonly yes
重启 redis
docker restart redis
设置开机自启动
docker update redis --restart=always
docker update mysql --restart=always