Docker 基础教程

Docker 安装

Docker 使用

Docker 实例

Docker 参考手册

Docker 安装 Redis


Docker 安装 Redis 主要有 2 种方法,分别是直接通过 docker 命令安装或通过 Dockerfile 构建。redis 相关的 docker 镜像所有版本可以查看镜像库的 redis tags,官方地址为 https://hub.docker.com/_/redis?tab=tags

方式一:docker pull redis

关键字搜索相关镜像

首先通过 redis 关键字查询当前镜像库的所有 redis 相关的镜像,使用 docker search 命令,具体示例如下:

knowledgedict@Mac ~ $ docker search redis
NAME                             DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
redis                            Redis is an open source key-value store th...   8458      [OK]       
bitnami/redis                    Bitnami Redis Docker Image                      157                  [OK]
sameersbn/redis                                                                  80                   [OK]
grokzen/redis-cluster            Redis cluster 3.0, 3.2, 4.0, 5.0, 6.0           70                   
rediscommander/redis-commander   Alpine image for redis-commander - Redis m...   45                   [OK]
kubeguide/redis-master           redis-master with "Hello World!"                32                   
redislabs/redis                  Clustered in-memory database engine compat...   25                   
redislabs/redisearch             Redis With the RedisSearch module pre-load...   23                   
oliver006/redis_exporter          Prometheus Exporter for Redis Metrics. Su...   22                   
arm32v7/redis                    Redis is an open source key-value store th...   21                   
bitnami/redis-sentinel           Bitnami Docker Image for Redis Sentinel         14                   [OK]
webhippie/redis                  Docker images for Redis                         12                   [OK]
redislabs/redisgraph             A graph database module for Redis               11                   [OK]
s7anley/redis-sentinel-docker    Redis Sentinel                                  10                   [OK]
arm64v8/redis                    Redis is an open source key-value store th...   9                    
insready/redis-stat              Docker image for the real-time Redis monit...   9                    [OK]
redislabs/redisinsight           RedisInsight - The GUI for Redis                9                    
redislabs/redismod               An automated build of redismod - latest Re...   7                    [OK]
goodsmileduck/redis-cli          redis-cli on alpine                             6                    [OK]
centos/redis-32-centos7          Redis in-memory data structure store, used...   5                    
circleci/redis                   CircleCI images for Redis                       5                    [OK]
clearlinux/redis                 Redis key-value data structure server with...   2                    
wodby/redis                      Redis container image with orchestration        1                    [OK]
tiredofit/redis                  Redis Server w/ Zabbix monitoring and S6 O...   1                    [OK]
xetamus/redis-resource           forked redis-resource                           0                    [OK]

拉取指定版本的镜像

从镜像库拉取镜像用 docker pull 命令。

knowledgedict@Mac ~ $ docker pull redis:6
6: 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:6

下载完成后,可以在本地的镜像列表查看相关信息,如下:

knowledgedict@Mac ~ $ docker images redis
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
redis               6                   1319b1eaa0b7        2 days ago          104 MB

运行容器

运行容器使用 docker run 命令,具体如下:

knowledgedict@Mac ~ $ docker run -itd --name redis-demo -p 6379:6379 redis:6
f9f8b148e56c6513e9425d55ac7eb9094d26318fafd638070c820f83ebc09726

启动后,查看相应容器运行信息:

knowledgedict@Mac ~ $ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
e7c369e590fd        redis:6             "docker-entrypoint..."   2 seconds ago       Up 1 second         0.0.0.0:6379->6379/tcp   redis-demo