Redis config doesn't setup on docker - docker

I tried to specify Redis config in the Dockerfile:
FROM redis:7.0.0
EXPOSE 6379
COPY redis.conf /usr/local/etc/redis/redis.conf
CMD ["redis-server", "--include /usr/local/etc/redis/redis.conf"]
But in logs:
redis_1 | 1:C 14 Nov 2022 12:32:28.045 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1 | 1:C 14 Nov 2022 12:32:28.045 # Redis version=7.0.5, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1 | 1:C 14 Nov 2022 12:32:28.045 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis_1 | 1:M 14 Nov 2022 12:32:28.046 * monotonic clock: POSIX clock_gettime
redis_1 | 1:M 14 Nov 2022 12:32:28.050 * Running mode=standalone, port=6379.
redis_1 | 1:M 14 Nov 2022 12:32:28.051 # Server initialized
And redis config doesn't work
With config I want to disable replica-read-only, which produces "Can't write against read-only replica" errors.

Related

Docker container fails to initalize from docker-compose

I am new to Docker and in the process of learning Docker Compose, using CentOS 8 as the host system. All of these files are in the same directory and marked executable with mode 0755.
My main application is in webapp.py:
import time
import redis
from flask import Flask
app = Flask(__name__)
cache = redis.Redis(host='redis', port=6379)
def get_hit_count():
retries = 5
while True:
try:
return cache.incr('hits')
except redis.exceptions.ConnectionError as exc:
if retries == 0:
raise exc
retries -= 1
time.sleep(0.5)
#app.route('/')
def hello():
count = get_hit_count()
return 'Hello World! I have been seen {} times.\n'.format(count)
There is a matching requirements.txt file:
flask
redis
A Dockerfile:
FROM python:3.4-alpine
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
CMD ["python", "webapp.py"]
And a docker-compose.yml file:
version: "3"
services:
web:
build: .
ports:
- "5000:5000"
stdin_open: true
tty: true
redis:
image: "redis:alpine"
However, when I run docker-compose up, it fails by exiting the web app. Compose outputs:
[root#localhost webappl]# docker-compose up
Starting webappl_redis_1 ... done
Starting webappl_web_1 ... done
Attaching to webappl_web_1, webappl_redis_1
redis_1 | 1:C 27 Dec 2021 09:03:35.861 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1 | 1:C 27 Dec 2021 09:03:35.861 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1 | 1:C 27 Dec 2021 09:03:35.861 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis_1 | 1:M 27 Dec 2021 09:03:35.863 * monotonic clock: POSIX clock_gettime
redis_1 | 1:M 27 Dec 2021 09:03:35.864 * Running mode=standalone, port=6379.
redis_1 | 1:M 27 Dec 2021 09:03:35.864 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_1 | 1:M 27 Dec 2021 09:03:35.864 # Server initialized
redis_1 | 1:M 27 Dec 2021 09:03:35.864 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. 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.
redis_1 | 1:M 27 Dec 2021 09:03:35.865 * Loading RDB produced by version 6.2.6
redis_1 | 1:M 27 Dec 2021 09:03:35.865 * RDB age 4147 seconds
redis_1 | 1:M 27 Dec 2021 09:03:35.865 * RDB memory usage when created 0.77 Mb
redis_1 | 1:M 27 Dec 2021 09:03:35.865 # Done loading RDB, keys loaded: 0, keys expired: 0.
redis_1 | 1:M 27 Dec 2021 09:03:35.865 * DB loaded from disk: 0.000 seconds
redis_1 | 1:M 27 Dec 2021 09:03:35.865 * Ready to accept connections
webappl_web_1 exited with code 0
Why does it exit?
can you trying adding following to your web: after ports:? if stdin_open doesn't work, try stdin
stdin_open: true
tty: true

Adding Sentinel ANNOUNCE_IP after container is up via entrypoint.sh

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?

Redis cluster in docker-swarm mode updated recipe

Anyone has a working recipe of Redis cluster in swarm mode? I tried everything I know and searched the internet but seems like an impossible task.
Here is what I have so far:
version: '3.4'
services:
redis-master:
image: redis
networks:
- redisdb
ports:
- 6379:6379
volumes:
- redis-master:/data
redis-slave:
image: redis
networks:
- redisdb
command: redis-server --slaveof redis-master 6379
volumes:
- redis-slave:/data
sentinel:
image: redis
networks:
- redisdb
ports:
- 26379:26379
command: >
bash -c "echo 'port 26379' > sentinel.conf &&
echo 'dir /tmp' >> sentinel.conf &&
echo 'sentinel monitor redis-master redis-master 6379 2' >> sentinel.conf &&
echo 'sentinel down-after-milliseconds redis-master 5000' >> sentinel.conf &&
echo 'sentinel parallel-syncs redis-master 1' >> sentinel.conf &&
echo 'sentinel failover-timeout redis-master 5000' >> sentinel.conf &&
cat sentinel.conf &&
redis-server sentinel.conf --sentinel"
links:
- redis-master
- redis-slave
volumes:
redis-master:
driver: local
redis-slave:
driver: local
networks:
redisdb:
attachable: true
driver: overlay
I use the following command to deploy as a service:
docker stack deploy --compose-file docker-compose-test.yml redis
The result is deployed services, were redis-master and redis-slave are connecting and I can see the synchronization processes happening as follows:
redis-master log:
1:C 16 Oct 2019 04:19:42.720 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 16 Oct 2019 04:19:42.720 # Redis version=5.0.6, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 16 Oct 2019 04:19:42.720 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1:M 16 Oct 2019 04:19:42.723 * Running mode=standalone, port=6379.
1:M 16 Oct 2019 04:19:42.723 # 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:M 16 Oct 2019 04:19:42.723 # Server initialized
1:M 16 Oct 2019 04:19:42.723 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. 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.
1:M 16 Oct 2019 04:19:42.723 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
1:M 16 Oct 2019 04:19:42.723 * Ready to accept connections
1:M 16 Oct 2019 04:19:43.976 * Replica 10.0.27.2:6379 asks for synchronization
1:M 16 Oct 2019 04:19:43.976 * Full resync requested by replica 10.0.27.2:6379
1:M 16 Oct 2019 04:19:43.976 * Starting BGSAVE for SYNC with target: disk
1:M 16 Oct 2019 04:19:43.976 * Background saving started by pid 15
15:C 16 Oct 2019 04:19:43.982 * DB saved on disk
15:C 16 Oct 2019 04:19:43.982 * RDB: 0 MB of memory used by copy-on-write
1:M 16 Oct 2019 04:19:44.053 * Background saving terminated with success
1:M 16 Oct 2019 04:19:44.053 * Synchronization with replica 10.0.27.2:6379 succeeded
Redis-slave log:
1:C 16 Oct 2019 04:19:40.776 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 16 Oct 2019 04:19:40.776 # Redis version=5.0.6, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 16 Oct 2019 04:19:40.776 # Configuration loaded
1:S 16 Oct 2019 04:19:40.779 * Running mode=standalone, port=6379.
1:S 16 Oct 2019 04:19:40.779 # 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:S 16 Oct 2019 04:19:40.779 # Server initialized
1:S 16 Oct 2019 04:19:40.779 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. 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.
1:S 16 Oct 2019 04:19:40.779 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
1:S 16 Oct 2019 04:19:40.779 * Ready to accept connections
1:S 16 Oct 2019 04:19:40.779 * Connecting to MASTER redis-master:6379
1:S 16 Oct 2019 04:19:40.817 # Unable to connect to MASTER: Invalid argument
1:S 16 Oct 2019 04:19:41.834 * Connecting to MASTER redis-master:6379
1:S 16 Oct 2019 04:19:41.851 # Unable to connect to MASTER: Invalid argument
1:S 16 Oct 2019 04:19:42.866 * Connecting to MASTER redis-master:6379
1:S 16 Oct 2019 04:19:42.942 # Unable to connect to MASTER: Invalid argument
1:S 16 Oct 2019 04:19:43.970 * Connecting to MASTER redis-master:6379
1:S 16 Oct 2019 04:19:43.975 * MASTER <-> REPLICA sync started
1:S 16 Oct 2019 04:19:43.975 * Non blocking connect for SYNC fired the event.
1:S 16 Oct 2019 04:19:43.975 * Master replied to PING, replication can continue...
1:S 16 Oct 2019 04:19:43.976 * Partial resynchronization not possible (no cached master)
1:S 16 Oct 2019 04:19:43.977 * Full resync from master: 39bb36f74ef0cdefdc08a2dc8d4a86112ea69f12:0
1:S 16 Oct 2019 04:19:44.053 * MASTER <-> REPLICA sync: receiving 175 bytes from master
1:S 16 Oct 2019 04:19:44.054 * MASTER <-> REPLICA sync: Flushing old data
1:S 16 Oct 2019 04:19:44.054 * MASTER <-> REPLICA sync: Loading DB in memory
1:S 16 Oct 2019 04:19:44.054 * MASTER <-> REPLICA sync: Finished with success
Redis-sentinel log:
port 26379
port 26379
dir /tmp
dir /tmp
sentinel monitor redis-master redis-master 6379 2
sentinel monitor redis-master redis-master 6379 2
sentinel down-after-milliseconds redis-master 5000
sentinel down-after-milliseconds redis-master 5000
sentinel parallel-syncs redis-master 1
sentinel parallel-syncs redis-master 1
sentinel failover-timeout redis-master 5000
sentinel failover-timeout redis-master 5000
1:X 16 Oct 2019 04:19:49.506 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
*** FATAL CONFIG FILE ERROR ***
1:X 16 Oct 2019 04:19:49.506 # Redis version=5.0.6, bits=64, commit=00000000, modified=0, pid=1, just started
1:X 16 Oct 2019 04:19:49.506 # Configuration loaded
Reading the configuration file, at line 3
>>> 'sentinel monitor redis-master redis-master 6379 2'
1:X 16 Oct 2019 04:19:49.508 * Running mode=sentinel, port=26379.
1:X 16 Oct 2019 04:19:49.508 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
Can't resolve master instance hostname.
1:X 16 Oct 2019 04:19:49.511 # Sentinel ID is aad9553d4999951f3b37eede5968b4aa262c07a9
1:X 16 Oct 2019 04:19:49.511 # +monitor master redis-master 10.0.27.5 6379 quorum 2
1:X 16 Oct 2019 04:19:49.512 * +slave slave 10.0.27.2:6379 10.0.27.2 6379 # redis-master 10.0.27.5 6379
1:X 16 Oct 2019 04:19:54.514 # +sdown slave 10.0.27.2:6379 10.0.27.2 6379 # redis-master 10.0.27.5 6379
So the slave-announce-ip, replica-announce-ip etc are having issues:
1- because the ips keep changing
2- Overlay networks ips are not always what they show they are
So failover dose not work and if master went down slave dont kick in!

How do you fix the warning "Redis must be restarted after THP is disabled" on Windows 10?

I have a docker-compose.yml file. When I run this, I get the warning "Redis must be restarted after THP is disabled".
Below is my docker-compose.yml:
version: '3'
services:
myapp:
# container_name: myapp
restart: always
build: .
ports:
- '52000:52000'
# - '8080:8080'
# - '4300:4300'
# - '4301:4301'
command: ["./wait-for-it.sh", "redis:6379", "--", "npm", "start"]
links:
- redis
- mongo
mongo:
# container_name: myapp-mongo
image: 'mongo:latest'
ports:
- '28107:28107'
# - '27017:27017'
redis:
# container_name: myapp-redis
# restart: always
image: 'redis:4.0.11'
# command: ["redis-server", "--appendonly", "yes"]
ports:
- '6379:6379'
Below are my logs:
redis_1 | 1:C 24 Sep 10:21:09.224 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1 | 1:C 24 Sep 10:21:09.236 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1 | 1:C 24 Sep 10:21:09.236 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis_1 | 1:M 24 Sep 10:21:09.239 * Running mode=standalone, port=6379.
redis_1 | 1:M 24 Sep 10:21:09.239 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_1 | 1:M 24 Sep 10:21:09.239 # Server initialized
mongo_1 | 2019-09-24T10:21:10.304+0000 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
redis_1 | 1:M 24 Sep 10:21:09.239 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
redis_1 | 1:M 24 Sep 10:21:09.239 * Ready to accept connections
# WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
From the error you could use 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' on docker host to fix your problem.
But, I know you are on windows & cannot access hyper-v MobyLinuxVM, so you should use workaround as next:
docker-compose.yaml:
version: '3'
services:
redis:
image: 'redis:4.0.11'
ports:
- '6379:6379'
depends_on:
- helper
sysctls:
- net.core.somaxconn=511
helper:
image: alpine
command: sh -c "echo never > /sys/kernel/mm/transparent_hugepage/enabled"
privileged: true
Above will first start a helper container which will set never for /sys/kernel/mm/transparent_hugepage/enabled, as all containers will share the same kernel of host, so your redis container which start later will also benefit from this, see next execution log:
PS E:\abc> docker-compose up
Starting abc_helper_1 ... done
Recreating 29ea8bfaeafc_abc_redis_1 ... done
Attaching to abc_helper_1, abc_redis_1
redis_1 | 1:C 25 Sep 15:38:17.822 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1 | 1:C 25 Sep 15:38:17.822 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1 | 1:C 25 Sep 15:38:17.822 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis_1 | 1:M 25 Sep 15:38:17.822 * Running mode=standalone, port=6379.
redis_1 | 1:M 25 Sep 15:38:17.823 # Server initialized
redis_1 | 1:M 25 Sep 15:38:17.823 * DB loaded from disk: 0.000 seconds
redis_1 | 1:M 25 Sep 15:38:17.823 * Ready to accept connections

Redis : Creating Server TCP listening socket *:6379: unable to bind socket, errno: 13

# develop.yml
redis:
image: redis
command: redis-server --requirepass 123
ports:
- '6379:6379'
expose:
- "6379
docker-compose -f develop.yml up redis shows:
docker-compose -f develop.yml up redis
Starting django-blog_redis_1 ... done
Attaching to django-blog_redis_1
redis_1 | 1:C 16 Nov 2018 03:52:46.935 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1 | 1:C 16 Nov 2018 03:52:46.935 # Redis version=5.0.1, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1 | 1:C 16 Nov 2018 03:52:46.935 # Configuration loaded
redis_1 | 1:M 16 Nov 2018 03:52:46.935 # Creating Server TCP listening socket *:6379: unable to bind socket, errno: 13
I check the port:
fuser -k -n tcp 6379
but nothing use 6379.
How can I solve it?
My os: Deepin Linux.
It seems that the problem is with deepin.
Execute the following command to solve it:
sudo apt remove apparmor
Related discussion: https://github.com/docker/for-linux/issues/413

Resources