在使用Docker时,在Redis启动时解决警告的正确方法是什么?

Bru*_*zio 8 redis docker

当我运行我的Redis Docker镜像时,我会面临以下警告:

# Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
( ... )
# WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
( ... )
# 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.
Run Code Online (Sandbox Code Playgroud)

在我在互联网上找到的解决方案中,这个看起来涵盖了一切,但是当我在Docker范围内尝试它(例如:更改我的Dockerfile以应用它们)时,我得到错误"只读文件系统".手动示例给出了同样的问题:

[root@769368ed0fc5 /]# sysctl -w net.core.somaxconn=65535
sysctl: setting key "net.core.somaxconn": Read-only file system
[root@769368ed0fc5 /]# echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf
[root@769368ed0fc5 /]# sysctl vm.overcommit_memory=1
sysctl: setting key "vm.overcommit_memory": Read-only file system
[root@769368ed0fc5 /]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
bash: /sys/kernel/mm/transparent_hugepage/enabled: Read-only file system
[root@769368ed0fc5 /]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
bash: /sys/kernel/mm/transparent_hugepage/enabled: Read-only file system
Run Code Online (Sandbox Code Playgroud)

有谁知道如何以正确的方式解决它?我发现了许多解决方法,例如:

  • 以特权模式运行容器
  • 在容器中挂载host/proc
  • 使用主机网络堆栈(--net = host)

我想知道在Docker中处理它的正确方法是什么.将提供有关提议的解决方案的技术解释的答案.