compose.yaml
version: '3.9'
services:
redis:
image: redis
restart: always
ports:
- 6178:6379
volumes:
- redis_data_a:/data
entrypoint: redis-server --appendonly yes
with-pw:
image: redis
restart: always
ports:
- 6179:6379
volumes:
- redis_data_b:/data
env_file: .env
entrypoint: redis-server --appendonly yes --requirepass ${REDIS_PASSWORD}
volumes:
redis_data_a:
redis_data_b:
networks:
default:
name: redis_network
.env
REDIS_PASSWORD=abc
This compose file yields:
redis://localhost:6179
redis://localhost:6178
docker compose pull
- gets the lastest redis imagedocker compose up
- runs the redis databases via Docker compose in the foreground (e.g. blocking)docker compose up -d
- runs the redis databases via Docker compose in the background (e.g. non-blocking). This blocks the PORT value too.
docker compose ps
-- see all docker compose services that are runningdocker ps
-- see all docker containers that are running (similar but different)
docker compose down
- stop + keep database data. Frees up the PORT value (regardless of how docker compose is running)docker compose down --rmi all -v
- DANGER - this will stop the database running AND delete all data.
docker compose -f compose.other.yaml
Anything after-f
needs to be a docker compose file. Consider using this for staging.
redis-cli -h localhost -p 6178 PING
Should respond with PONG
redis-cli -h localhost -p 6179 PING
Should respond with (error) NOAUTH Authentication required.
Using auth:
redis-cli -h localhost -p 6179
Then use the abc
password set in .env
file:
> auth abc
Using Redis in the Redis shell (redis-cli
):
set some_key some_value
get some_key
These method(s) will work for redis that has auth and redis that doesnt. If redis has auth, you must authenticated before these commands will work.