Valkey: Use Docker Compose for Valkey as alternative to Redis

As Redis changed its license to a proprietary one, the Linux Foundation created a fork called Valkey, which has a BSD license.
"Valkey is an open source high-performance key/value datastore that supports a variety of workloads such as caching, message queues, and can act as a primary database. Valkey can run as either a standalone daemon or in a cluster, with options for replication and high availability."
In an earlier blog entry, we created a Redis cluster using Docker Compose. Now we'll do the same for Valkey.
Here's my YAML file:
services:
db1:
image: valkey/valkey
hostname: valkey1
ports:
- 6379:6379
command: valkey-server --bind 0.0.0.0 --cluster-enabled yes --cluster-config-file nodes.conf --cluster-node-timeout 3000 --appendonly yes --appendfilename appendonly.aof
Let's pull the image
# docker compose pull
[+] Pulling 8/8
✔ db1 Pulled 3.0s
✔ d9b636547744 Already exists 0.0s
✔ 99cfdd9ca5fb Pull complete 0.4s
✔ 789e542f5600 Pull complete 0.6s
✔ ef776d73991b Pull complete 1.2s
✔ e979fefdd81a Pull complete 1.2s
✔ 4f4fb700ef54 Pull complete 1.3s
✔ 9e5d4e035f87 Pull complete 1.3s
... and start the container:
# docker compose up -d
[+] Running 2/2
✔ Network valkey Created 0.1s
✔ Container valkey-db1-1 Started 0.3s
db1-1 | 1:M 17 Apr 2025 09:03:18.651 # WARNING: Changing databases number from 16 to 1 since we are in cluster mode
db1-1 | 1:M 17 Apr 2025 09:03:18.651 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
db1-1 | 1:M 17 Apr 2025 09:03:18.653 * oO0OoO0OoO0Oo Valkey is starting oO0OoO0OoO0Oo
db1-1 | 1:M 17 Apr 2025 09:03:18.653 * Valkey version=8.1.0, bits=64, commit=00000000, modified=0, pid=1, just started
db1-1 | 1:M 17 Apr 2025 09:03:18.653 * Configuration loaded
db1-1 | 1:M 17 Apr 2025 09:03:18.654 * monotonic clock: POSIX clock_gettime
db1-1 | 1:M 17 Apr 2025 09:03:18.654 * Running mode=cluster, port=6379.
db1-1 | 1:M 17 Apr 2025 09:03:18.655 * No cluster configuration found, I'm a5aa651ca20b611bb1756d44f276fd5a0a8bca9e
db1-1 | 1:M 17 Apr 2025 09:03:18.659 * Server initialized
db1-1 | 1:M 17 Apr 2025 09:03:18.662 * Creating AOF base file appendonly.aof.1.base.rdb on server start
db1-1 | 1:M 17 Apr 2025 09:03:18.666 * Creating AOF incr file appendonly.aof.1.incr.aof on server start
db1-1 | 1:M 17 Apr 2025 09:03:18.666 * Ready to accept connections tcp
db1-1 | 1:M 17 Apr 2025 09:03:20.672 # Cluster is currently down: I am part of a minority partition.
If you now want to create a Valkey cluster, you can do the same commands I used at the Redis blog entry. You can also use the redis
commands
# redis-cli -h
valkey-cli 8.1.0
Usage: valkey-cli [OPTIONS] [cmd [arg [arg ...]]]
[...]
... or stay in Valkey flavor and use the valkey
commands
# valkey-cli -h
valkey-cli 8.1.0
Usage: valkey-cli [OPTIONS] [cmd [arg [arg ...]]]
[...]