# Docker 安装 Redis

Redis 是一个开源的使用 ANSI C 语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value 的 NoSQL 数据库，并提供多种语言的 API。

### 1、查看可用的 Redis 版本

访问 Redis 镜像库地址： <https://hub.docker.com/_/redis?tab=tags>。

可以通过 Sort by 查看其他版本的 Redis，默认是最新版本 **redis:latest**。

![](/files/W95VwopFt1y5GC2fF7zK)

你也可以在下拉列表中找到其他你想要的版本：

![](/files/N9xnbTRCEYU9XlPEiyxi)

此外，我们还可以用 **docker search redis** 命令来查看可用版本：

```shell
docker search  redis
NAME                      DESCRIPTION                   STARS  OFFICIAL  AUTOMATED
redis                     Redis is an open source ...   2321   [OK]       
sameersbn/redis                                         32                   [OK]
torusware/speedus-redis   Always updated official ...   29             [OK]
bitnami/redis             Bitnami Redis Docker Image    22                   [OK]
anapsix/redis             11MB Redis server image ...   6                    [OK]
webhippie/redis           Docker images for redis       4                    [OK]
clue/redis-benchmark      A minimal docker image t...   3                    [OK]
williamyeh/redis          Redis image for Docker        3                    [OK]
unblibraries/redis        Leverages phusion/baseim...   2                    [OK]
greytip/redis             redis 3.0.3                   1                    [OK]
servivum/redis            Redis Docker Image            1                    [OK]
...
```

### 2、取最新版的 Redis 镜像

这里我们拉取官方的最新版本的镜像：

```shell
docker pull redis:latest
```

![](/files/Rb9YUxPNyp7Diskp9G91)

### 3、查看本地镜像

使用以下命令来查看是否已安装了 redis：

```shell
docker images
```

![](/files/JRS4eqU1T9rZlnimheax)

在上图中可以看到我们已经安装了最新版本（latest）的 redis 镜像。

### 4、运行容器

安装完成后，我们可以使用以下命令来运行 redis 容器：

```shell
docker run -itd --name redis-test -p 6379:6379 redis
```

**参数说明：**

* **-p 6379:6379**：映射容器服务的 6379 端口到宿主机的 6379 端口。外部可以直接通过宿主机ip:6379 访问到 Redis 的服务。

![](/files/hcLNo5CCG2Tg2NdussMw)

### 5、安装成功

最后我们可以通过 **docker ps** 命令查看容器的运行信息：

![](/files/fBMD7scAbJlkgdn1Q5vr)

接着我们通过 redis-cli 连接测试使用 redis 服务。

```shell
docker exec -it redis-test /bin/bash
```

![](/files/doZ4e2mJpG944xQSCU7g)

### 6、进阶使用

[Docker redis进阶配置](/docker/advanced/docker-redis-advanced.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tuonioooo-notebook.gitbook.io/docker/install/docker-install-redis.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
