docker安装redis
2022-10-10 本文已影响0人
阿畅00000
一、搜索redis镜像
命令:docker search <镜像名称>
[root@nightmare-01 kerwin]# docker search redis
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
redis Redis is an open source key-value store that… 11397 [OK]
bitnami/redis Bitnami Redis Docker Image 229 [OK]
bitnami/redis-sentinel Bitnami Docker Image for Redis Sentinel 39 [OK]
bitnami/redis-cluster 34
redis/redis-stack redis-stack installs a Redis server with add… 15
rapidfort/redis RapidFort optimized, hardened image for Redi… 15
rapidfort/redis-cluster RapidFort optimized, hardened image for Redi… 15
circleci/redis CircleCI images for Redis 14 [OK]
ubuntu/redis Redis, an open source key-value store. Long-… 11
redis/redis-stack-server redis-stack-server installs a Redis server w… 10
bitnami/redis-exporter 9
clearlinux/redis Redis key-value data structure server with t… 4
ibmcom/redis-ha 1
bitnami/redis-sentinel-exporter 1
ibmcom/ibm-cloud-databases-redis-operator Container image for the IBM Operator for Red… 1
rapidfort/redis6-ib RapidFort optimized, hardened image for Redi… 0
vmware/redis-photon 0
cimg/redis 0
rancher/redislabs-ssl 0
ibmcom/redis-ppc64le 0
drud/redis redis 0 [OK]
corpusops/redis https://github.com/corpusops/docker-images/ 0
blackflysolutions/redis Redis container for Drupal and CiviCRM 0
ibmcom/redisearch-ppc64le 0
greenbone/redis-server A redis service container image for the Gree… 0
二、拉取镜像
命令:docker pull <镜像名称>:<版本号>
[root@nightmare-01 kerwin]# docker pull redis
Using default tag: latest
latest: Pulling from library/redis
bd159e379b3b: Pull complete
729b630784ac: Pull complete
065c77bf222a: Pull complete
961784053f68: Pull complete
b42f16846808: Pull complete
0f1fa5bb0033: Pull complete
Digest: sha256:c95835a74c37b3a784fb55f7b2c211bd20c650d5e55dae422c3caa9c01eb39fa
Status: Downloaded newer image for redis:latest
docker.io/library/redis:latest
三、准备redis挂载配置文件
1.挂载的目的在于:以配置文件方式启动redis容器,不需要进容器内修改配置,直接在宿主机上修改配置文件也会随之修改容器内配置文件。
2.准备两个文件夹:挂载配置文件(/kerwin/install/redis/myredis01/redis.conf) 和redis数据持久化(/kerwin/install/redis/myredis01/data)
四、启动redis容器
docker run --restart=always --log-opt max-size=100m --log-opt max-file=2 -p 6379:6379 --name myredis01 -v /kerwin/install/redis/myredis01/redis.conf:/etc/redis/redis.conf -v /kerwin/install/redis/myredis01/data:/data -d redis redis-server /etc/redis/redis.conf --appendonly yes --requirepass wu1234
1.--restart=always 总是开机启动。
2.--log是日志方面的。
3.-p 6379:6379 将6379端口挂载出去。
4.--name 给这个容器取一个名字。
5.-v 数据卷挂载
/kerwin/install/redis/myredis01/redis.conf:/etc/redis/redis.conf 这里是将 liunx 路径下的redis.conf 和redis容器下的redis.conf 挂载在一起,
/kerwin/install/redis/myredis01/data:/data 这个同上。
6.-d redis 表示后台启动redis。
7.redis-server /etc/redis/redis.conf 以配置文件启动redis,加载容器内的conf文件。
8.--appendonly yes 开启redis 持久化。
9.--requirepass wu1234 设置密码 。
五、测试
1.通过docker ps -a 指令查看启动状态
[root@nightmare-01 myredis01]# docker ps -a | grep myredis
466a946ca3ae redis "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp myredis01
2.查看容器日志
docker logs --since 30m 466a946ca3ae
image.png
3.容器内获取key,并设置密码。
[root@nightmare-01 ~]# docker exec -it 466a946ca3ae redis-cli
127.0.0.1:6379> get a
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth wu1234
OK
127.0.0.1:6379> get a
(nil)
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) "wu1234"
127.0.0.1:6379>