1.拉取redis镜像
docker pull redis
拉取完成
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest a617c1c92774 3 years ago 105MB
2.运行redis容器
docker run -itd --name redis-test01 -p 6379:6379 redis:latest
运行成功
[root@localhost ~]# docker run -itd --name redis-test01 -p 6379:6379 redis:latest
caaefdf803a37ba0dfc02b96b42392ec97924b7174c24cca2c159568fb7ca636
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
caaefdf803a3 redis:latest "docker-entrypoint.s…" 3 seconds ago Up 2 seconds 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp redis-test01
3.进入redis容器
[root@localhost ~]# docker exec -it redis-test01 /bin/bash
root@caaefdf803a3:/data# redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set name yohoo
OK
127.0.0.1:6379> set age 28
OK
rdm管理工具连接
4.启动时加载配置文件并挂载rdb文件
docker run -itd --name redis01 -v /root/redis/redis01/redis.conf:/redisConfig/redis.conf -p 6379:6379 redis:latest redis-server /redisConfig/redis.conf
启动
[root@localhost redis01]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3a83b1765745 redis:latest "docker-entrypoint.s…" 3 seconds ago Up 3 seconds 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp redis01
进入容器
redis.conf已映射
root@205c0f28bd62:/redisConfig# ls
redis.conf
redis客户端连接并创建一些数据
root@edb62ab155e0:/redisConfig# redis-cli -a 123456 #这里需要密码是因为本人引入的redis.conf中设置了密码
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> set name kunkun
OK
127.0.0.1:6379> set age 25
OK
127.0.0.1:6379> set address nanjing
OK
注意事项
- redis.conf的daemonize表示是否以守护进程执行
- docker run命令中的-d也是守护进程的意思
- 为了防止冲突要修改redis.conf配置文件,把daemonize修改成no