- I want to boot a redis container with a password set on it
- I dont want to use the redis.conf file for doing this
I created a Dockerfile initially which works wonders
FROM redis:7
USER redis
CMD ["redis-server", "--requirepass", "123456789"]
Ran redis-cli inside container
redis-cli -a '123456789'
and verified that commands work by doing a simple SET val to 1 and retrieving it But as you can see, putting your password inside a Dockerfile is a bad idea ATTEMPT 1 I created a .env.docker file with the password set inside
REDIS_SESSION_PASSWORD=123456789
and modified my Dockerfile as follows
FROM redis:7
USER redis
CMD ["redis-server", "--requirepass", "$REDIS_SESSION_PASSWORD"]
and built it with the command below
docker build -t cache_server_image -f ./docker/development/cache/Dockerfile .
docker run -p 6379:6379 --env-file .env.docker -v cache_data:/data --name cache_server cache_server_image && docker logs cache_server --follow
When I run docker inspect I can see all the variables set When I run the same redis-cli command I get an error now
AUTH failed: WRONGPASS invalid username-password pair or user is disabled.
Attempt 2 Tried a little variation in the Dockerfile
FROM redis:7
USER redis
CMD ["redis-server", "--requirepass", "${REDIS_SESSION_PASSWORD}"]
Still got the same error again? I assume that the Dockerfile is not able to read the value of redis session password inside CMD. Any ideas how I can fix this?