Set Redis container password in docker-compose

1. Option 1:

        Add the command command directly in the docker-compose.yml file.

version: "3.8"

networks:
  flask_li:

services:
  redis:
    image: redis:7.0.11
    container_name: my_redis
    restart: always
    ports:
      - "6379:6379"
    command: redis-server --requirepass yourpassword
    volumes:
      - ./data/redis/data:/data

        Then execute docker-compose up -d directly in the directory where it is located to generate a Redis container with a password in Docker.

2. Scheme 2

version: "3.8"

networks:
  flask_li:

services:
  redis:
    image: redis:7.0.11
    container_name: my_redis
    restart: always
    ports:
      - "6379:6379"
    command: redis-server /usr/local/etc/redis/redis.conf
    volumes:
      - ./data/redis/data:/data
      - ./data/redis/config/redis.conf:/usr/local/etc/redis/redis.conf

Among them: command represents the command to be executed after the container is generated.

Set password in redis.conf:

3. Summary

        The advantage of option 2 is that you can customize the configuration of Redis more. The advantage of option 1 is that you can quickly start a Docker Redis instance with password-free without relying on external redis.conf.

Guess you like

Origin blog.csdn.net/weixin_44799217/article/details/131079990