Redis – Fix Warnings with Dockerfile

I have a redis service in my docker application:

docker-compose-dev.yml

 web:
    build:
      context: ./services/web
      dockerfile: Dockerfile-dev
    volumes:
      - './services/web:/usr/src/app'

    ports:
      - 5001:5000
    environment:
      - FLASK_ENV=development
      - APP_SETTINGS=brandio.config.DevelopmentConfig
      - DATABASE_URL=postgres://postgres:[email protected]:5432/web_dev 
      - DATABASE_TEST_URL=postgres://postgres:[email protected]:5432/web_test
      - SECRET_KEY=my_precious  
    depends_on:  
      - web-db
      - redis

  redis:
    image: redis:5.0.3-alpine
    restart: always
    expose:
      - '6379'
    ports:
      - '6379:6379'

but my network seems to be clogging due to some memory issues.

Log:

redis_1 | 1:C 09 May 2019 21:06:32.979 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1 | 1:C 09 May 2019 21:06:32.981 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1 | 1:C 09 May 2019 21:06:32.981 # 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 09 May 2019 21:06:32.986 * Running mode=standalone, port=6379.
redis_1 | 1:M 09 May 2019 21:06:32.986 # 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 09 May 2019 21:06:32.986 # Server initialized
redis_1 | 1:M 09 May 2019 21:06:32.986 # 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.

In order to fix these warnings, I have followed this very cited link:

Tips for Redis Server

  1. Raise somaxconn above 511
    1417:M 25 Oct 06:13:31.840 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
    To fix this warning you have to set a new config to /etc/rc.local so that the setting will persist upon reboot

$~: sudo nano /etc/rc.local

Add this:

sysctl -w net.core.somaxconn=65535

When you reboot the next time, the new setting will be to allow 65535 connections instead of 128 as before.


and:

  1. Disable THP
    1417:M 25 Oct 06:13:31.840 # 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
    This is also simple to fix by just running the recommended command as stated in the warning.

echo never > /sys/kernel/mm/transparent_hugepage/enabled

Go to /etc/rc.local

$~: sudo nano /etc/rc.local

Add this:

echo never > /sys/kernel/mm/transparent_hugepage/enabled

I performed those tips on my local machine and did reboot, but warning persists.

So far I have only a Dockerfile for my web service.

How do I fix these Redis warnings using Dockerfile?

Source: StackOverflow