简单介绍下docker搭建单机redis
1、查找镜像,docker search redis
[root@*** opt]# docker search redis
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
redis Redis is an open source key-value store that… 7426 [OK]
bitnami/redis Bitnami Redis Docker Image 129 [OK]
sameersbn/redis 77 [OK]
grokzen/redis-cluster Redis cluster 3.0, 3.2, 4.0 & 5.0 61
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… 23
oliver006/redis_exporter Prometheus Exporter for Redis Metrics. Supp… 18
arm32v7/redis Redis is an open source key-value store that… 17
redislabs/redisearch Redis With the RedisSearch module pre-loaded… 17
2、拉取镜像,docker pull redis
[root@*** opt]# docker pull redis
Using default tag: latest
latest: Pulling from library/redis
8d691f585fa8: Already exists
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
3、启动redis,开启aof持久化
[root@*** opt]# docker run -d -p 6379:6379 -v $PWD/data:/data redis redis-server --appendonly yes
0c9f0a163ae06f7edd628bd02307bf140d51fd4f2605f7e14dce8f7b76f5bc9c
[root@*** opt]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0c9f0a163ae0 redis "docker-entrypoint.s…" 22 seconds ago Up 21 seconds 0.0.0.0:6379->6379/tcp peaceful_kare
[root@*** opt]# ls
containerd data
4、查看redis信息
[root@*** opt]# docker exec -it 0c9f0a163ae0 redis-cli
127.0.0.1:6379> info
# Server
redis_version:5.0.6
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:24cefa6406f92a1f
redis_mode:standalone
os:Linux 3.10.0-327.el7.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
atomicvar_api:atomic-builtin
gcc_version:8.3.0
process_id:1
run_id:3540d77f00ff9a23daa5004c81dbb4fecefa1f27
tcp_port:6379
uptime_in_seconds:687
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:11383985
executable:/data/redis-server
.
.
.
5、测试
package com.su.mybatis.oracle.controller;
import redis.clients.jedis.Jedis;
public class Test {
/**
* @param args
* @author sucb
* @date 2019-10-21
*/
public static void main(String[] args) {
Jedis jedis = new Jedis("xxx.xxx.xxx.xxx", 6379);//redis服务器IP、端口
jedis.ping();
jedis.set("test", "su");
System.out.println(jedis.get("test"));
jedis.close();
}
}
输出结果:
su
redis容器:
127.0.0.1:6379> get test
"su"
如果有写的不对的地方,请大家多多批评指正,非常感谢!