上一篇我们介绍了在传统的Linux机器上如何安装redis,本次我们来看看怎么在docker环境中安装redis

  • 拉取docker镜像

使用docker安装软件时,第一步需要将镜像拉取下来,我们使用docker search redis 命令来搜索redis镜像(使用默认的镜像源搜索或下载很慢,可以看我的另一篇docker配置阿里云镜像设置国内镜像)

查看docker版本:

[root@localhost bin]# docker --version
Docker version 19.03.8, build afacb8b

 搜索redis镜像:

[root@localhost bin]# docker search redis
NAME                             DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
redis                            Redis is an open source key-value store that…   8509                [OK]                
bitnami/redis                    Bitnami Redis Docker Image                      158                                     [OK]
sameersbn/redis                                                                  80                                      [OK]

我们选用第一个官方版本,使用docker pull redis下载镜像到本地,默认下载最新版

[root@localhost bin]# docker pull redis
Using default tag: latest
latest: Pulling from library/redis
bf5952930446: Pull complete 
911b8422b695: Pull complete 
093b947e0ade: Pull complete 
5b1d5f59e382: Pull complete 
7a5f59580c0b: Pull complete 
f9c63997c980: Pull complete 
Digest: sha256:09c33840ec47815dc0351f1eca3befe741d7105b3e95bc8fdb9a7e4985b9e1e5
Status: Downloaded newer image for redis:latest
docker.io/library/redis:latest
  •  查看已下载的镜像:docker images
[root@localhost bin]# docker images
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
redis                latest              1319b1eaa0b7        2 weeks ago         104MB
  • 下载对应版本的redis.conf配置文件redis.conf
  • 建立数据目录和redis配置文件目录
mkdir /data/redis/redis-data

上传已下载的redis.conf配置文件到/data/redis/redis-conf/目录(可自定义)

修改配置文件

vi redis.conf

修改bind 127.0.0.1 为 bind 0.0.0.0 
//如果设置为127.0.0.1则其他机器无法访问
修改后台守护进程启动
daemonize yes 改为 daemonize no
  • 启动镜像
docker run -p 6379:6379 -v /usr/local/docker/redis.conf:/data/redis/redis-conf/redis.conf  -v /opt/redis/log/redis.log:/data/redis/redis-log/redis.log --name=redis 1319b1eaa0b7

 

GitHub 加速计划 / li / linux-dash
13
2
下载
A beautiful web dashboard for Linux
最近提交(Master分支:4 个月前 )
186a802e added ecosystem file for PM2 5 年前
5def40a3 Add host customization support for the NodeJS version 5 年前
Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐