Docker中使用Redis


1、查看可用的 Redis 版本

[root@vultr ~]# docker search redis
INDEX       NAME                                       DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/redis                            Redis is an open source key-value store th...   10428     [OK]
docker.io   docker.io/grokzen/redis-cluster            Redis cluster 3.0, 3.2, 4.0, 5.0, 6.0, 6.2      83
docker.io   docker.io/rediscommander/redis-commander   Alpine image for redis-commander - Redis m...   72                   [OK]
docker.io   docker.io/redislabs/redisearch             Redis With the RedisSearch module pre-load...   47
docker.io   docker.io/redislabs/rejson                 RedisJSON - Enhanced JSON data type proces...   39
docker.io   docker.io/redislabs/redisinsight           RedisInsight - The GUI for Redis                35
docker.io   docker.io/redislabs/redis                  Clustered in-memory database engine compat...   32
docker.io   docker.io/oliver006/redis_exporter          Prometheus Exporter for Redis Metrics. Su...   31
docker.io   docker.io/arm32v7/redis                    Redis is an open source key-value store th...   24
docker.io   docker.io/arm64v8/redis                    Redis is an open source key-value store th...   19
docker.io   docker.io/redislabs/rebloom                A probablistic datatypes module for Redis       18                   [OK]
docker.io   docker.io/redislabs/redisgraph             A graph database module for Redis               17                   [OK]
docker.io   docker.io/redislabs/redismod               An automated build of redismod - latest Re...   17                   [OK]
docker.io   docker.io/webhippie/redis                  Docker image for redis                          11                   [OK]
docker.io   docker.io/insready/redis-stat              Docker image for the real-time Redis monit...   10                   [OK]
docker.io   docker.io/redislabs/redistimeseries        A time series database module for Redis         10
docker.io   docker.io/s7anley/redis-sentinel-docker    Redis Sentinel                                  10                   [OK]
docker.io   docker.io/goodsmileduck/redis-cli          redis-cli on alpine                             9                    [OK]
docker.io   docker.io/centos/redis-32-centos7          Redis in-memory data structure store, used...   6
docker.io   docker.io/clearlinux/redis                 Redis key-value data structure server with...   3
docker.io   docker.io/runnable/redis-stunnel           stunnel to redis provided by linking conta...   1                    [OK]
docker.io   docker.io/tiredofit/redis                  Redis Server w/ Zabbix monitoring and S6 O...   1                    [OK]
docker.io   docker.io/wodby/redis                      Redis container image with orchestration        1                    [OK]
docker.io   docker.io/flant/redis-sentinel-proxy       Redis sentinel proxy by enriclluelles writ...   0                    [OK]
docker.io   docker.io/xetamus/redis-resource           forked redis-resource                           0                    [OK]

2、取最新版的 Redis 镜像

[root@vultr ~]# docker image pull docker.io/redis
Using default tag: latest
Trying to pull repository docker.io/library/redis ...
latest: Pulling from docker.io/library/redis
a2abf6c4d29d: Pull complete
c7a4e4382001: Pull complete
4044b9ba67c9: Pull complete
c8388a79482f: Pull complete
413c8bb60be2: Pull complete
1abfd3011519: Pull complete
Digest: sha256:db485f2e245b5b3329fdc7eff4eb00f913e09d8feb9ca720788059fdc2ed8339
Status: Downloaded newer image for docker.io/redis:latest

3、查看镜像是否拉取成功

[root@vultr ~]# docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/redis     <none>              aea9b698d7d1        5 weeks ago         113 MB

4、运行容器

4.1、修改配置文件


4.2、启动

[root@vultr ~]# docker run -itd --name docker-redis -p 6379:6379 redis
77e5c14c7de9f33ab626a3d66422306472996a7ccdb3a74345e83615d2d31a16

5、查看状态

[root@vultr ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                    NAMES
77e5c14c7de9        redis               "docker-entrypoint..."   About a minute ago   Up 59 seconds       0.0.0.0:6380->6379/tcp   docker-redis

6、查看启动状态

注:此处 77e5c14c7de9 为步骤5中的容器ID

[root@vultr ~]# docker logs 77e5c14c7de9
1:C 12 Jan 2022 09:28:55.252 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 12 Jan 2022 09:28:55.252 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 12 Jan 2022 09:28:55.252 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1:M 12 Jan 2022 09:28:55.253 * monotonic clock: POSIX clock_gettime
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 6.2.6 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 1
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           https://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

1:M 12 Jan 2022 09:28:55.255 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:M 12 Jan 2022 09:28:55.255 # Server initialized
1:M 12 Jan 2022 09:28:55.255 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
1:M 12 Jan 2022 09:28:55.255 * Ready to accept connections

7、连接登录测试

[root@vultr ~]# docker exec -it docker-redis /bin/bash
root@77e5c14c7de9:/data# redis-cli
127.0.0.1:6379> keys *
(empty array)
127.0.0.1:6379> set name Gipsy
OK
127.0.0.1:6379> get name
"Gipsy"


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM