Docker启动Redis容器时报错WARNING: The TCP backlog setting of 511 cannot be enforced

正常使用命令

docker pull redis

之后启动        

docker run --name m-redis -p 8379:6379 -v /data/redis/redis.conf:/usr/local/etc/redis/redis.conf -d redis

发现容器并没有启动,于是查看了一下logs 

[root@localhost redis]# docker logs m-redis
1:C 25 Sep 2023 04:03:47.852 # 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.
1:C 25 Sep 2023 04:03:47.852 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 25 Sep 2023 04:03:47.852 * Redis version=7.2.1, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 25 Sep 2023 04:03:47.852 # 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 25 Sep 2023 04:03:47.852 * monotonic clock: POSIX clock_gettime
1:M 25 Sep 2023 04:03:47.852 * Running mode=standalone, port=6379.
1:M 25 Sep 2023 04:03:47.852 # 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 25 Sep 2023 04:03:47.853 # Fatal: Can't initialize Background Jobs. Error message: Operation not permitted

下意识得修改了宿主机的 /proc/sys/net/core/somaxconn 文件

echo 511 > /proc/sys/net/core/somaxconn

发现并没有什么卵用。考虑是镜像内的文件, 于是修改创建容器命令为

docker run -p 8379:6379 --name m-redis \
--sysctl net.core.somaxconn=1024 \
-v /data/docker/m-redis/data:/data \
-v /data/docker/m-redis/conf/redis.conf:/usr/local/etc/redis/redis.conf \
-e TIME_ZONE="Asia/Shanghai" \
-e TZ="Asia/Shanghai" \
-d --restart=always \
--privileged=true \
redis

docker ps 查看解决问题了

[root@localhost redis]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                         PORTS               NAMES
b9f99c1d5fe1        redis               "docker-entrypoint..."   9 minutes ago       Restarting (1) 2 minutes ago                       m-redis
[root@localhost redis]# 

你可能感兴趣的:(docker,redis,tcp/ip)