安装好docker后,在docker上安装mysql , redis,nacos
1. mysql
下载镜像
docker pull mysql:5.7
创建实例并启动
docker run -p 3306: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 3306:3306 将容器的3306端口映射到主机的3306端口
-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 初始化root用户密码
查看运行中的容器
docker ps
配置mysql
vi /mydata/mysql/conf/my.cnf
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqlId]
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
skie-name-resolve
docker restart mysql
2. 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持久化配置
vi redis.conf //编辑配置文件
appendonly yes
3. nacos
docker pull nacos/nacos-server
mkdir -p /root/nacos/init.d /root/nacos/logs
touch /root/nacos/init.d/custom.properties
management.endpoints.web.exposure.include=*
docker run -d -p 8848:8848
-e MODE=standalone -e PREFER_HOST_MODE=hostname
-v /root/nacos/init.d/custom.properties:/home/nacos/init.d/custom.properties
-v /root/nacos/logs:/home/nacos/logs --name nacos nacos/nacos-server
设置开机启动
docker update redis --restart=always
docker update mysql --restart=always
docker update nacos --restart=always