一、安装Redis
- 环境
名称 | 版本 | 备注 | |
---|---|---|---|
虚拟机 | VMware® Workstation 15 Pro | ||
centos7 | 1810 | ||
docker | 19.03.1 | ||
Redis | 7.4.3 |
- 查询镜像
[root@master ~]# docker search redis
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
redis Redis is an open source key-value store that… 7536 [OK]
bitnami/redis Bitnami Redis Docker Image 131 [OK]
sameersbn/redis 78 [OK]
grokzen/redis-cluster Redis cluster 3.0, 3.2, 4.0 & 5.0 62
rediscommander/redis-commander Alpine image for redis-commander - Redis man… 31 [OK]
kubeguide/redis-master redis-master with "Hello World!" 30
redislabs/redis Clustered in-memory database engine compatib… 24
arm32v7/redis Redis is an open source key-value store that… 19
oliver006/redis_exporter Prometheus Exporter for Redis Metrics. Supp… 18
redislabs/redisearch Redis With the RedisSearch module pre-loaded… 17
webhippie/redis Docker images for Redis 10 [OK]
s7anley/redis-sentinel-docker Redis Sentinel 9 [OK]
insready/redis-stat Docker image for the real-time Redis monitor… 9 [OK]
bitnami/redis-sentinel Bitnami Docker Image for Redis Sentinel 8 [OK]
redislabs/redisgraph A graph database module for Redis 8 [OK]
arm64v8/redis Redis is an open source key-value store that… 6
redislabs/redismod An automated build of redismod - latest Redi… 5 [OK]
centos/redis-32-centos7 Redis in-memory data structure store, used a… 4
circleci/redis CircleCI images for Redis 2 [OK]
frodenas/redis A Docker Image for Redis 2 [OK]
runnable/redis-stunnel stunnel to redis provided by linking contain… 1 [OK]
tiredofit/redis Redis Server w/ Zabbix monitoring and S6 Ove… 1 [OK]
wodby/redis Redis container image with orchestration 1 [OK]
xetamus/redis-resource forked redis-resource 0 [OK]
cflondonservices/redis Docker image for running redis 0
- 拉取镜象
[root@master ~]# docker pull redis
Using default tag: latest
latest: Pulling from library/redis
8d691f585fa8: Pull complete
8ccd02d17190: Pull complete
4719eb1815f2: Pull complete
200531706a7d: Pull complete
eed7c26916cf: Pull complete
e1285fcc6a46: Pull complete
Digest: sha256:fe80393a67c7058590ca6b6903f64e35b50fa411b0496f604a85c526fb5bd2d2
Status: Downloaded newer image for redis:latest
docker.io/library/redis:latest
[root@master ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest de25a81a5a0b 4 weeks ago 98.2MB
- 创建容器
# 创建镜像
[root@master ~]# docker run -p 6379:6379 -d redis:latest redis-server
0ffdfb70bbfb6cf7e13d213a3f34ddd934990f102262da78784067cf790913c2
# 数据挂载到容器
[root@master ~]# docker run -p 6379:6379 -v $PWD/data:/data -d redis:latest redis-server --appendonly yes
# 查看容器网络
[root@master ~]# docker inspect 0ffdfb70bbfb | grep IPAddress
"SecondaryIPAddresses": null,
"IPAddress": "172.17.0.3",
"IPAddress": "172.17.0.3",
命令说明:
-p 6379:6379 : 将容器的6379端口映射到主机的6379端口
-v $PWD/data:/data : 将主机中当前目录下的data挂载到容器的/data
redis-server --appendonly yes : 在容器执行redis-server启动命令,并打开redis持久化配置
- 连接redis的几种方式
[root@master ~]# docker exec -ti 0ffdfb70bbfb redis-cli
127.0.0.1:6379>
[root@master ~]# docker exec -ti 0ffdfb70bbfb redis-cli -h localhost -p 6379
[root@master ~]# docker exec -ti 0ffdfb70bbfb redis-cli -h 127.0.0.1 -p 6379
[root@master ~]# docker exec -ti 0ffdfb70bbfb redis-cli -h 172.17.0.3 -p 6379
注意,这个是容器运行的ip,可通过 docker inspect redis_s | grep IPAddress 查看