$ docker run --name some-redis -d redis redis-server --requirepass foobared
# verify it worked with
$ docker run -it --link some-redis:redis --rm redis redis-cli -h redis -p 6379
redis:6379> AUTH test
(error) ERR invalid password
redis:6379> AUTH foobared
OK
redis:6379>
This could be abstracted to an environment variable trivially via something like:
$ docker run --name some-redis -d -e REDIS_PASSWORD=foobared redis sh -c 'exec redis-server --requirepass "$REDIS_PASSWORD"'
redis:
restart: always
container_name: app-redis
build:
context: ./docker/images/redis
dockerfile: Dockerfile
ports:
- "6379:6379"
volumes:
- ./docker/images/redis/data:/data
command: redis-server --requirepass ${REDIS_PASSWORD:-123456}
$ docker run --name some-redis -d redis redis-server --requirepass foobared
# verify it worked with
$ docker run -it --link some-redis:redis --rm redis redis-cli -h redis -p 6379
redis:6379> AUTH test
(error) ERR invalid password
redis:6379> AUTH foobared
OK
redis:6379>
This could be abstracted to an environment variable trivially via something like:
$ docker run --name some-redis -d -e REDIS_PASSWORD=foobared redis sh -c 'exec redis-server --requirepass "$REDIS_PASSWORD"'
redis:
restart: always
container_name: app-redis
build:
context: ./docker/images/redis
dockerfile: Dockerfile
ports:
- "6379:6379"
volumes:
- ./docker/images/redis/data:/data
command: redis-server --requirepass ${REDIS_PASSWORD:-123456}