一般情况下,linux 环境安装 redis,需要编译安装,配置,启动服务等步骤,需要一点时间,而使用 docker 进行 redis 部署,迅速简洁,过程也较为间单。
首先使用 docker 搜索 redis
[root@192]# docker search redis NAME DESCRIPTION STARS OFFICIAL AUTOMATED redis Redis is an open source key-value store that… 6653 [OK] bitnami/redis Bitnami Redis Docker Image 106 [OK] sameersbn/redis 76 [OK] grokzen/redis-cluster Redis cluster 3.0, 3.2, 4.0 & 5.0 44 hypriot/rpi-redis Raspberry Pi compatible redis image 33 kubeguide/redis-master redis-master with "Hello World!" 28 rediscommander/redis-commander Alpine image for redis-commander - Redis man… 21 [OK] redislabs/redis Clustered in-memory database engine compatib… 19 redislabs/redisearch Redis With the RedisSearch module pre-loaded… 15 arm32v7/redis Redis is an open source key-value store that… 14 oliver006/redis_exporter Prometheus Exporter for Redis Metrics. Supp… 10 webhippie/redis Docker images for Redis 10 [OK] s7anley/redis-sentinel-docker Redis Sentinel 7 [OK] insready/redis-stat Docker image for the real-time Redis monitor… 7 [OK] arm64v8/redis Redis is an open source key-value store that… 5 rtoma/logspout-redis-logstash Logspout including Redis adapter for sending… 5 redislabs/redisgraph A graph database module for Redis 4 [OK] centos/redis-32-centos7 Redis in-memory data structure store, used a… 4 frodenas/redis A Docker Image for Redis 2 [OK] circleci/redis CircleCI images for Redis 2 [OK] wodby/redis Redis container image with orchestration 2 [OK] tiredofit/redis Redis Server w/ Zabbix monitoring and S6 Ove… 1 [OK] cflondonservices/redis Docker image for running redis 0 xetamus/redis-resource forked redis-resource 0 [OK] iadvize/redis 0
使用第一个 redis 镜像
docker pull redis
下载完成后,查看镜像
[root@192]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE redis latest 0f88f9be5839 11 days ago 95MB
使用该镜像声称容器
[root@192]# docker run --name olo -p 6379:6379 -v /data/program/docker_redis:/data/program/docker_redis -d redis redis-server /data/program/docker_redis/redis.conf appendonly yes
run,生成一个容器
--name,容器名
-p,端口映射,即将容器的端口 6379 映射到主机的端口 6379,当访问主机 6379 时,即会连接到该容器的 6379
-v,文件路径映射,主机目录/data/program/docker_redis,映射到容器目录/data/program/docker_redis
-d,后台运行
redis,使用该镜像
redis-server /data/program/docker_redis/redis.conf,启动 redis 服务器,使用该目录下的 redis.conf 配置表
----appendonly yes,开启持久化
然后,就可使用
[root@192]# docker exec -it olo redis-cli
或直接使用
[root@192]# redis-cli 127.0.0.1:6379> select 4 OK 127.0.0.1:6379[4]>
即可连接到该 redis 数据库,数据存放路径以及日志路径可在 redis.conf 中进行配置。
综上,一共需要 3 步,
1.下载镜像
2.配置需要映射文件和 redis.conf
3.生成容器
然后即可使用 redis 数据库
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于