docker安装redis单节点

2022-10-27 13:35:02 浏览数 (2)

# 1.创建文件目录

代码语言:javascript复制
[root@summer redis]# mkdir -p /docker/redis/data
[root@summer redis]# mkdir -p /docker/redis/conf

这里我copy了一份redis-5.0.8/redis.conf

代码语言:javascript复制
[root@summer redis]# cp /home/summer/redis-5.0.8/redis.conf /docker/redis/conf/

修改默认配置文件

  • bind 127.0.0.1 #注释掉这部分,这是限制redis只能本地访问
  • protected-mode no #默认yes,开启保护模式,限制为本地访问
  • daemonize no#默认no,改为yes意为以守护进程方式启动,可后台运行,除非kill进程(可选),改为yes会使配置文件方式启动redis失败
  • dir ./ #输入本地redis数据库存放文件夹(可选)
  • appendonly yes #redis持久化(可选)

# 2.pull镜像

代码语言:javascript复制
[root@summer ~]# docker pull redis:5.0.8
5.0.8: Pulling from library/redis
123275d6e508: Pull complete 
f2edbd6a658e: Pull complete 
66960bede47c: Pull complete 
533694cb3638: Pull complete 
1dc100dcb2f1: Pull complete 
9ca9ac709269: Pull complete 
Digest: sha256:96bdb5e2984b15e3cf4de74077f650c911cb26ec0981e0772df35a1a5cb19798
Status: Downloaded newer image for redis:5.0.8
docker.io/library/redis:5.0.8
[root@summer ~]# docker images
REPOSITORY                                      TAG                 IMAGE ID            CREATED             SIZE
redis                                           5.0.8               975fe4b9f798        6 months ago        98.3MB

# 3.创建容器

代码语言:javascript复制
[root@summer conf]# docker run --name summer-redis -p 6666:6379 -v /docker/redis/data:/data -v /docker/redis/conf/redis.conf:/etc/redis/redis.conf -d redis:5.0.8 redis-server /etc/redis/redis.conf --appendonly yes
9dfcbc6fc9e087cd291554753ddd467655cfc4971c0f2c6adb5926a3e808f368

# 4.验证

代码语言:javascript复制
[root@summer conf]# docker ps 
CONTAINER ID        IMAGE              COMMAND                  CREATED             STATUS              PORTS                           NAMES
9dfcbc6fc9e0        redis:5.0.8        "docker-entrypoint.s…"   49 seconds ago      Up 48 seconds       0.0.0.0:6666->6379/tcp       summer-redis

0 人点赞