SoFunction
Updated on 2025-03-10

Docker's practical guide to viewing and modifying Redis container passwords

Preface

When deploying Redis containers using Docker, sometimes we need to view or modify the password of Redis. This article will introduce in detail how to view and modify the password of the Redis container in Docker to help you better manage and maintain your Redis instances.

1. Check the Redis container password

Usually when starting a Redis container, we will set the Redis password through the Redis configuration file or environment variable. If you forget this password, you can check it in the following ways:

1. Check the Docker startup command

If you remember the command when starting the Redis container, you can check the environment variables in the command or

Configuration file path:

docker run --name redis-container -e REDIS_PASSWORD=my-secret-pw -d redis --requirepass my-secret-pw

In this command, my-secret-pw is the password of Redis.

2. View Docker Compose file

If the Redis container is started through Docker Compose, you can view the file:

version: '3.1'

services:
  redis:
    image: redis:latest
    environment:
      - REDIS_PASSWORD=my-secret-pw
    command: ["redis-server", "--requirepass", "my-secret-pw"]

In the environment section or command section, you can find the password for Redis.

3. View container configuration file

If you cannot view the startup command or Docker Compose file directly, you can enter the container to view the Redis configuration file (such as):

docker exec -it redis-container bash
cat /usr/local/etc/redis/ | grep requirepass

The requiredpass configuration item and its corresponding password will be displayed in the output.

2. Modify the Redis container password

If you need to modify the password of the Redis container, you can do it through the following steps:

1. Enter the Redis container

First, enter the interactive terminal of the Redis container:

docker exec -it redis-container bash

2. Log in to Redis

Inside the container, log in to Redis via redis-cli:

redis-cli

If Redis has a password set, authentication is required first:

AUTH current-secret-pw

3. Change password

After logging in successfully, use the Redis command to modify the password:

CONFIG SET requirepass "new-secret-pw"

4. Exit and restart the container

Exit the Redis CLI:

exit

Exit the container:

exit

Finally, restart the Redis container to ensure that the new password takes effect:

docker restart redis-container

3. Summary

Through the methods described in this article, you can easily view and modify the password of the Redis container in Docker. Whether it is through startup commands, Docker Compose files, or configuration files within a container, these steps can help you better manage your Redis instance.

The above is the detailed content of Docker's practical guide to viewing and modifying Redis container passwords. For more information about Docker's viewing and modifying Redis passwords, please follow my other related articles!