docker安装redis

查看redis版本

docker search redis查看,或者登录网站查看

[root@localhost ~]# docker search redis
NAME                                DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
redis                               Redis is an open source key-value store that…   12522               [OK]                
bitnami/redis                       Bitnami Redis Docker Image                      271                                     [OK]
redislabs/redisinsight              RedisInsight - The GUI for Redis                94                                      
redis/redis-stack                   redis-stack installs a Redis server with add…   85                                      
redis/redis-stack-server            redis-stack-server installs a Redis server w…   62                                      
redislabs/redisearch                Redis With the RedisSearch module pre-loaded…   61                                      
redislabs/rejson                    RedisJSON - Enhanced JSON data type processi…   53                                      
redislabs/redismod                  An automated build of redismod - latest Redi…   41                                      [OK]
redislabs/redis                     Clustered in-memory database engine compatib…   40                                      
redislabs/redisgraph                A graph database module for Redis               26                                      [OK]
redislabs/rebloom                   A probablistic datatypes module for Redis       25                                      [OK]
redislabs/redistimeseries           A time series database module for Redis         12                                      
redislabs/operator                                                                  7                                       
redislabs/redisai                                                                   6                                       
redislabs/redis-py                                                                  5                                       
redislabs/redis-webcli              A tiny Flask app to provide access to Redis …   5                                       [OK]
redislabs/redisgears                An automated build of RedisGears                4                                       
redislabs/redisml                   A Redis module that implements several machi…   3                                       [OK]
redislabs/k8s-controller                                                            2                                       
redislabs/operator-internal         This repository contains pre-released versio…   1                                       
redislabs/olmtest                   Test artefact for OLM CSV                       1                                       
redislabs/ng-redis-raft             Redis with redis raft module                    0                                       
redislabs/k8s-controller-internal                                                   0                                       
redislabs/olm-bundle                                                                0                                       
redislabs/memtier_benchmark         Docker image to run memtier_benchmark           0     

下载指定版本

[root@localhost ~]# 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
[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
redis               5.0.8               975fe4b9f798        3 years ago         98.3MB

docker挂载配置文件
接下来就是要将redis 的配置文件进行挂载,以配置文件方式启动redis 容器。(挂载:即将宿主的文件和容器内部目录相关联,相互绑定,在宿主机内修改文件的话也随之修改容器内部文件)

1)、挂载redis的配置文件
2)、挂载redis 的持久化文件(为了数据的持久化)。

配置文件路径例如:

[root@localhost ~]# mkdir -p /home/redis/redis5.0.8
[root@localhost ~]# cd /home/redis/redis5.0.8/
[root@localhost redis5.0.8]# mkdir data
[root@localhost redis5.0.8]# 
[root@localhost redis5.0.8]# ls
data  redis.conf

redis.conf 可以通过官网下载

docker启动redis

docker run --restart=always -p 6378:6378 --name redis5.0.8 \
-v /home/redis/redis5.0.8/data:/data \
-v /home/redis/redis5.0.8/redis.conf:/etc/redis/redis.conf \
-d redis:5.0.8 \
 redis-server /etc/redis/redis.conf  --requirepass Admin_123
  • –restart=always 总是开机启动
  • -p 6379:6379 将6379端口挂载出去
  • –name 给这个容器取一个名字
  • -v 数据卷挂载。/home/redis/redis5.0.8/redis.conf:/etc/redis/redis.conf 这里是将 liunx 路径下的redis.conf 和redis下的redis.conf 挂载在一起。/home/redis/redis5.0.8/data:/data 这个同上。
  • -d 指定要使用的 Redis 镜像及版本号,并在后台运行容器
  • redis-server /etc/redis/redis.conf 以配置文件启动redis,加载容器内的conf文件,最终找到的是挂载的目录 /etc/redis/redis.conf 也就是liunx下的/home/redis/redis5.0.8/redis.conf
  • –appendonly yes 开启redis 持久化
  • –requirepass 000000 设置密码 (如果想向外开放的话,一定要设置)

测试

查看启用状态

[root@localhost redis5.0.8]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                              NAMES
3e30b4ca313c        redis:5.0.8         "docker-entrypoint.s…"   4 minutes ago       Up 4 minutes        0.0.0.0:6378->6378/tcp, 6379/tcp   redis5.0.8

查看容器运行日志

docker logs --since 30m redis5.0.8

容器内部进行连接

[root@localhost redis5.0.8]# docker exec -it redis5.0.8 redis-cli -p 6378

重启

docker restart redis

docker删除redis

docker ps -a
docker stop <容器名>
docker rm <容器名>

docker images  # 查看所有镜像
docker rmi <IMAGE ID> #删除

你可能感兴趣的:(docker,docker,redis,容器)