docker icon indicating copy to clipboard operation
docker copied to clipboard

Running Docker exec with user www-data ignores Redis configuration whereas sudo does not

Open Midnighter opened this issue 3 years ago • 0 comments

I'm running the nextcloud:24.0-apache image and have defined the Redis password using the following in my docker-compose.yml (ignoring a bunch of configuration):

services:
  nextcloud:
    image: nextcloud:24.0-apache
    secrets:
      - redis_password
    environment:
      - "REDIS_HOST=redis"
      - "REDIS_HOST_PASSWORD_FILE=/run/secrets/redis_password"

  redis:
    image: redis:7.0-alpine
    command: ["redis-server", "/usr/local/etc/redis/redis.conf"]
    volumes:
      - "./redis.conf:/usr/local/etc/redis/redis.conf"

This works perfectly in general. However, I then wanted to set up a cron job from the host using Docker exec and noticed a discrepancy.

The following command does not pick up the Redis configuration (probably Docker does not provide the necessary environment variables to the user).

docker exec --user www-data --tty $(docker ps --quiet --filter 'name=nextcloud_nextcloud') php -d memory_limit=512M -f /var/www/html/cron.php

which causes a missing password error

RedisException: WRONGPASS invalid username-password pair or user is disabled. in /var/www/html/lib/private/RedisFactory.php:143                                                       

However, when I run the container as root and then execute php as the www-data user via sudo, it works.

docker exec --tty $(docker ps --quiet --filter 'name=nextcloud_nextcloud') sudo --user www-data php -d memory_limit=512M -f /var/www/html/cron.php

Is this expected, anything I should do about that?

Midnighter avatar Sep 14 '22 15:09 Midnighter