Skip to content

Commit 5684e37

Browse files
committed
add redis environment
1 parent fd82c5b commit 5684e37

File tree

2 files changed

+1357
-0
lines changed

2 files changed

+1357
-0
lines changed

redis/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
2+
### 1. 相关资源
3+
4+
- 镜像地址:https://store.docker.com/images/redis
5+
- redis 发布地址:https://github.com/antirez/redis
6+
7+
拉取镜像
8+
9+
```
10+
# 默认拉取最新版本,目前是 4.0.1
11+
➜ docker pull redis
12+
13+
# 或指定版本
14+
➜ docker pull redis:3
15+
```
16+
检查镜像是否拉取成功
17+
18+
```
19+
➜ redis docker images
20+
REPOSITORY TAG IMAGE ID CREATED SIZE
21+
redis latest d4f259423416 5 weeks ago 106MB
22+
```
23+
24+
### 2. 使用
25+
26+
#### 2.1. 默认启动
27+
28+
```
29+
➜ redis docker run --name myredis -d redis
30+
41f9c2e8fb86c415257c0342eb58435c3a5bbaf10f888a2cb3c7243d08ec796c
31+
```
32+
之后就可以通过客户端程序连接 `127.0.0.1:6379` 来访问了
33+
34+
#### 2.2. 怎么使用 redis-cli 连接容器?
35+
36+
```bash
37+
➜ redis docker run -it --link myredis --rm redis redis-cli -h myredis -p 6379
38+
myredis:6379> KEYS *
39+
(empty list or set)
40+
myredis:6379> SET name 'xiaoming'
41+
OK
42+
myredis:6379> GET name
43+
"xiaoming"
44+
myredis:6379> exit
45+
```
46+
47+
#### 2.3. 如何将数据持久化存储到宿主机?
48+
49+
```bash
50+
➜ docker run --name myredis2 -d -v ~/data/redis:/data redis redis-server --appendonly yes
51+
```
52+
说明:
53+
54+
- `--appendonly yes` 用于打开 redis 的数据持久化存储
55+
- `-v ~/data/redis:/data` 用于将宿主机的目录映射到容器对应的数据存储目录
56+
57+
#### 2.4. 自定义配置文件
58+
59+
首先到 [https://github.com/antirez/redis/blob/unstable/redis.conf](https://github.com/antirez/redis/blob/unstable/redis.conf) 下载一份 redis 的默认配置文件,然后在 redis 容器启动时如下操作:
60+
61+
```bash
62+
# ~/myredis/conf/redis.conf 对应宿主机配置文件位置
63+
➜ docker run -v ~/myredis/conf/redis.conf:/usr/local/etc/redis/redis.conf --name myredis3 redis redis-server /usr/local/etc/redis/redis.conf
64+
```

0 commit comments

Comments
 (0)