Install and run redis on Docker

1 Install Docker on CentOS

First of all, you should docker on your CentOS, jump to the official page and learn how to install docker on cent os.

You can run the following commands to install docker on your CentOS.

 $ sudo yum install -y yum-utils   # pre install
 $ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo  # pull the repository of docker
 $ sudo yum-config-manager --enable docker-ce-nightly  # enabke some config
 $ sudo yum-config-manager --enable docker-ce-test     # enabke some config
 $ sudo yum install docker-ce docker-ce-cli containerd.io   # install it throuth yum

After you installed docker, you should test it.

 $ sudo systemctl start docker   # start docker service
 $ sudo docker run hello-world   # run hello world test

2 Install Redis on docker

First, use docker search redis to search all the redis version:

$ docker search redis
NAME                             DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
redis                            Redis is an open source key-value store that…   9611      [OK]       
bitnami/redis                    Bitnami Redis Docker Image                      185                  [OK]
sameersbn/redis                                                                  83                   [OK]
grokzen/redis-cluster            Redis cluster 3.0, 3.2, 4.0, 5.0, 6.0, 6.2      78                   
rediscommander/redis-commander   Alpine image for redis-commander - Redis man…   60                   [OK]
redislabs/redisearch             Redis With the RedisSearch module pre-loaded…   34                   
redislabs/redis                  Clustered in-memory database engine compatib…   31                   
redislabs/redisinsight           RedisInsight - The GUI for Redis                31                   
oliver006/redis_exporter          Prometheus Exporter for Redis Metrics. Supp…   28                   
arm32v7/redis                    Redis is an open source key-value store that…   24                   
redislabs/rejson                 RedisJSON - Enhanced JSON data type processi…   23                   
bitnami/redis-sentinel           Bitnami Docker Image for Redis Sentinel         23                   [OK]
redislabs/redisgraph             A graph database module for Redis               15                   [OK]
arm64v8/redis                    Redis is an open source key-value store that…   13                   
redislabs/redismod               An automated build of redismod - latest Redi…   13                   [OK]
redislabs/rebloom                A probablistic datatypes module for Redis       12                   [OK]
webhippie/redis                  Docker images for Redis                         11                   [OK]
s7anley/redis-sentinel-docker    Redis Sentinel                                  10                   [OK]
insready/redis-stat              Docker image for the real-time Redis monitor…   10                   [OK]
circleci/redis                   CircleCI images for Redis                       7                    [OK]
centos/redis-32-centos7          Redis in-memory data structure store, used a…   5                    
clearlinux/redis                 Redis key-value data structure server with t…   3                    
wodby/redis                      Redis container image with orchestration        1                    [OK]
tiredofit/redis                  Redis Server w/ Zabbix monitoring and S6 Ove…   1                    [OK]
xetamus/redis-resource           forked redis-resource                           0                    [OK]

And, install a version of reids, I have installed the official version.

$ docker pull redis:latest  # you can install the latest version of redis
$ docker images   # you can use this command to view how many images have been installed on docker

And then, create a redis image on docker.

$ docker run -itd --name redis-test -p 6379:6379 redis
$ docker ps   # you can view redis version by this command
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                                       NAMES
90f9bfe40ae4   redis     "docker-entrypoint.s…"   42 minutes ago   Up 42 minutes   0.0.0.0:6379->6379/tcp, :::6379->6379/tcp   redis-test

Finally, you can run redis on docker like this:

$ sudo docker run -it --name redis-test -d redis bash

Or like this:

$ sudo docker exec/run -it redis-test bash
# you can also use CONTAINER ID instead of NAMES
$ sudo docker exec/run -it 90f9bfe40ae4 bash

When you at this step, it’s not means you are started redis successfully, you need run it on a remote host:

$ redis -h [ip address or domain address] -p port 
# for example
$ redis -h 127.0.0.1 -p 6379
127.0.0.1:6379>   # when you see this line, it's means successful.

Reference Page

Could not connect to redis connection refused – Fix it easily

Install Docker Engine on CentOS

Install and Configure Redis on CentOS 7

Using Redis in Docker containers

写在最后

欢迎大家关注鄙人的公众号【麦田里的守望者zhg】,让我们一起成长,谢谢。
微信公众号

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值