# 安装redis

**1. 前提是Docker已经安装好了**

**2.拉取Redis镜像**

```shell
docker pull redis
```

**3.启动**

```shell
docker run --name redis -p 6378:6379 -d --restart=always redis redis-server --appendonly yes --requirepass "123456"
```

> 参数讲解
>
> `--name`为容器取一个唯一的名字
>
> `-p`端口映射，把宿主机的端口映射到容器内的端口
>
> `--restar=always`随容器启动而启动
>
> `redis-server --appendonly yes`在容器里执行`redis-server`命令，打开redis持久化
>
> `--requirepass`密码

**4.连接**

```
docker ps 查看CONTAINER ID
docker exec -it 0047b8680fc2 redis-cli
```


---

# 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://xn--6o0a585a.gitbook.io/devops/docker/centos7/an-zhuang-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.
