centos安装docker步骤 这里
启动docker服务
systemctl start docker
设置docker开机自启动
systemctl enable docker
查看所有镜像
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest 7faaec683238 7 months ago 113MB
tomcat 9.0 9427bc9144fa 8 months ago 680MB
nacos/nacos-server latest bdf60dc2ada3 10 months ago 1.05GB
hello-world latest d1165f221234 15 months ago 13.3kB
zookeeper 3.5.7 6bd990489b09 2 years ago 245MB
mysql 5.7.26 e9c354083de7 2 years ago 373MB
redis 3.2 87856cc39862 3 years ago 76MB
拉取mysql5.7版本镜像
docker pull mysql:5.7
运行镜像
docker run --name mysql
-v /mydata/mysql/data:/var/lib/mysql\
-v /mydata/mysql/conf:/etc/mysql\
-v /mydata/mysql/log:/var/log/mysql\
-e MYSQL_ROOT_PASSWORD=root\
-p 3306:3306 -d mysql:5.7
参数 -v /mydata/mysql/data:/var/lib/mysql\ 将数据文件挂载到主机 :前面的是主机目的地址:后面的是容器中的目录地址
-v /mydata/mysql/conf:/etc/mysql\ 将配置文件挂载到主机
-v /mydata/mysql/log:/var/log/mysql\ 将日志文件挂载到主机
查看运行的容器
docker ps
[root~]# docker p
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6f2e3327238f mysql:5.7.26 "docker-entrypoint.s…" 6 months ago Exited (0) 6 months ago mysql
进入到交互式mysql中
docker exec -it 6f2e3327238f /bin/bash
修改mysql的配置文件 设置字符编码等 vim /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
skip-character-set-client-handshake
skip-name-resolve
重启mysql docker restart mysql
安装redis
拉取镜像
docker pull redis
启动redis 创建文件夹 mkdir -p /mydata/redis/conf touch /mydata/redis/conf/redis.conf
docker run -p 6379:6379 --name redi -v /mydata/redis/data:/data\
-v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf\
-d redis redis-server /etc/redis/redis.conf --privileged=true
注意,最新版的命令不同,容器内的conf文件的位置变为了/usr/local/etc/redis/redis.conf
mkdir -p /mydata/redis/conf
touch /mydata/redis/conf/redis.con
进入到redis控制台
docker exec -it redis redis-cli
开启redis持久化 vim /mydata/redis/conf/redis.conf 加入
bind 0.0.0.0 开启远程权限
appendonly yes 开启aof持久化
重启redis docker restart redis