安装mysql
由于原本虚拟机安装了mysql 查看原来安装MySQL的端口号
netstat -anp|grep mysql
之前安装的端口号已经是3306,所以docker安装容器对应宿主机的端口不再使用3306端口
docker run -p 13306: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
-p 宿主机端口号 容器内mysql端口号
运行之后对mysql进行配置 进入到挂载目录
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
之后重启mysql即可
安装redis
拉取镜像
docker pull redis
启动redis镜像,同样因为虚拟机本身安装了redis,所以对应端口改为了16379
mkdir -p /mydata/redis/conf
touch /mydata/redis/conf/redis.conf
docker run -p 16379: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