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.

1
2
3
4
5
$ 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.

1
2
$ 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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$ 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.

1
2
$ 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.

1
2
3
4
$ 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:

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

Or like this:

1
2
3
$ 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:

1
2
3
4
$ 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】,让我们一起成长,谢谢。
微信公众号