Docker swarm-mode is tricky when it comes to IP addresses since the IP it shows not necessarily the one in use. This confuse Sentinel in swarm-mode. To get around this Im adding steps to sentinel-entrypoint to ANNOUNCE_IP after container in up and has its IP assigned.
I added the following to sentienl-entrypoint.sh:
ANNOUNCE_IP=$(awk "END{print $1}" /etc/hosts)
echo $ANNOUNCE_IP
if [ -n "$ANNOUNCE_IP" ]; then
echo "sentinel announce-ip $ANNOUNCE_IP" >> /usr/local/bin/sentinel.conf
fi
When containers start I see the following in log:
port 26379
dir /tmp
sentinel monitor docker-cluster redis_1 6379 3
sentinel down-after-milliseconds docker-cluster 5000
sentinel parallel-syncs docker-cluster 1
sentinel failover-timeout docker-cluster 5000
0
1:X 10 Oct 2019 16:26:55.426 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:X 10 Oct 2019 16:26:55.426 # Redis version=5.0.6, bits=64, commit=00000000, modified=0, pid=1,
just started
1:X 10 Oct 2019 16:26:55.426 # Configuration loaded
1:X 10 Oct 2019 16:26:55.427 * Running mode=sentinel, port=26379.
1:X 10 Oct 2019 16:26:55.427 # WARNING: The TCP backlog setting of 511 cannot be enforced because
/proc/sys/net/core/somaxconn is set to the lower value of 128.
1:X 10 Oct 2019 16:26:55.432 # Sentinel ID is 6c81c967eeed77e513166491ee0e6b989f261c74
1:X 10 Oct 2019 16:26:55.432 # +monitor master docker-cluster 10.0.0.159 6379 quorum 3
1:X 10 Oct 2019 16:26:55.433 * +slave slave 10.0.0.13:6379 10.0.0.13 6379 @ docker-cluster
10.0.0.159 6379
1:X 10 Oct 2019 16:27:00.450 # +sdown slave 10.0.0.13:6379 10.0.0.13 6379 @ docker-cluster
10.0.0.159 6379
For some unknown reason the IP address shows as 0, but when I log into the container and run the same command I get the IP of the container. Any ideas?