Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I set a password for redis? #176

Closed
ddzyan opened this issue Dec 6, 2018 · 13 comments
Closed

How do I set a password for redis? #176

ddzyan opened this issue Dec 6, 2018 · 13 comments
Labels
question Usability question, not directly related to an error with the image

Comments

@ddzyan
Copy link

ddzyan commented Dec 6, 2018

sudo docker run \
> -p 6379:6379 \
> -v $PWD/data:/data \
> --requirepass "__@picker-redis" \
> --name redis \
> -d redis:3.2 redis-server --appendonly yes
unknown flag: --requirepass
See 'docker run --help'.
@tao12345666333
Copy link
Contributor

You made the wrong position of the parameter.

You should do it, like this:

sudo docker run \
> -p 6379:6379 \
> -v $PWD/data:/data \
> --name redis \
> -d redis:3.2 redis-server --appendonly yes  --requirepass "__@picker-redis" 

@wglambert wglambert added the question Usability question, not directly related to an error with the image label Dec 6, 2018
@ddzyan
Copy link
Author

ddzyan commented Dec 6, 2018

You made the wrong position of the parameter.

You should do it, like this:

sudo docker run \
> -p 6379:6379 \
> -v $PWD/data:/data \
> --name redis \
> -d redis:3.2 redis-server --appendonly yes  --requirepass "__@picker-redis" 

Thank you, I will try

@brunowego
Copy link

Sharing this for other users:

Volume

docker volume create redis-data

Running

docker run -d \
  -h redis \
  -e REDIS_PASSWORD=redis \
  -v redis-data:/data \
  -p 6379:6379 \
  --name redis \
  --restart always \
  redis:5.0.5-alpine3.9 /bin/sh -c 'redis-server --appendonly yes --requirepass ${REDIS_PASSWORD}'

Remove

docker rm -f redis
docker volume rm redis-data

@jrichardsz
Copy link

This worked for me

docker run --name redis -d -p 6379:6379 redis redis-server --requirepass "SUPER_SECRET_PASSWORD"

@stevecho-dift
Copy link

This worked for me

docker run --name redis -d -p 6379:6379 redis redis-server --requirepass "SUPER_SECRET_PASSWORD"

This worked for me

docker run --name redis -d -p 6379:6379 redis redis-server --requirepass "SUPER_SECRET_PASSWORD"

Thanks mate. It worked for me too!

@CenkCamkiran
Copy link

--requirepass

Thanks mate!

@antonioGabrielGomes
Copy link

You made the wrong position of the parameter.

You should do it, like this:

sudo docker run \
> -p 6379:6379 \
> -v $PWD/data:/data \
> --name redis \
> -d redis:3.2 redis-server --appendonly yes  --requirepass "__@picker-redis" 

Do you know if is possible update an container redis with this --requirepass ?

@yosifkit
Copy link
Contributor

Do you know if is possible update an container redis with this --requirepass ?

It might be technically possible but I don't know of a container runtime that will restart a container with a new CMD.

With docker run, you need to stop and remove the old container and then start a new one with the new argument. Many tools like kubernetes or compose do this when you apply updated yaml config and then it deploys updated containers (they remove the old containers and replace them with new containers with the updated runtime configuration). Be sure to use a volume (or equivalent) for any important on-disk save state to have the new container able to pick up where the other stopped.

@wget
Copy link

wget commented Jul 4, 2023

For those wanting a syntax à-la Docker Compose v2, here you are:

  nextcloud-prod-redis:
    image: redis:7-alpine
    container_name: nextcloud-prod-redis
    hostname: nextcloud-prod-redis
    environment:
      - REDIS_PASSWORD=<cf. your password manager>
    volumes:
      - "/srv/cloud.example.org/data/redis:/data"
    networks:
      - nextcloud-prod-network
    command: /bin/sh -c 'redis-server --appendonly yes --requirepass $${REDIS_PASSWORD}'
    restart: always

The trick here was to double the $ character in order to avoid Docker Compose from interpreting it.

@hahuaz
Copy link

hahuaz commented Jul 30, 2023

For docker-compose.yml leave the username empty in the Redis URL.

redis:
  image: redis:latest
  container_name: redis
  command: /bin/sh -c "redis-server --requirepass redis"
  ports:
    - 6379:6379
express:
  stdin_open: true
  environment:
    - REDIS_URL=redis://:redis@redis:6379 # {service}://{username}:{password}@{host}:{port}
  build:
    context: .
    dockerfile: Dockerfile
  container_name: express-app
  depends_on:
    - redis
  ports:
    - "3000:3000"
  volumes:
    - ./:/app # enable reloading

@steelbrain
Copy link

There's a downside to doing it this way. Anyone doing a docker ps can see the password

@jrichardsz
Copy link

There's a downside to doing it this way. Anyone doing a docker ps can see the password

Anyone with access to the docker container will be able to see any secret no matter if it is encrypted with a DarkHold algorithm.

@VpkPrasanna

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Usability question, not directly related to an error with the image
Projects
None yet
Development

No branches or pull requests