docker - Redis 在 docker 容器中无故关闭

标签 docker redis docker-compose amazon-ecs

我正在尝试使用 docker-compose 启动一个 redis docker 容器,但我总是收到此错误。这是我的 docker-compose 运行命令 docker-compose -f docker-compose.yml builddocker-compose -f docker-compose.yml up -d --force-recreate .我正在 aws ecs 上运行 docker 容器并使用 t2.micro ec2 实例。我不确定这是否是原因。任何见解都会有所帮助。

我还包括了我的 docker-compose.yml

version: '2.1'

services:
  redis:
    image: redis:latest
    container_name: redis
    volumes: 
      - redis_data:/data
    ports: 
      - 6379:6379
  app:
    image: custom_image
    build: .
    depends_on:
      redis:
        condition: service_started
    ports:
      - 8003:8003
    links:
      - redis
volumes:
  redis_data:

错误
1:C 11 Sep 00:18:34.345 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 11 Sep 00:18:34.348 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 11 Sep 00:18:34.348 # 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 11 Sep 00:18:34.349 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
1:M 11 Sep 00:18:34.349 # Server can't set maximum open files to 10032 because of OS error: Operation not permitted.
1:M 11 Sep 00:18:34.349 # Current maximum open files is 4096. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
1:M 11 Sep 00:18:34.350 * Running mode=standalone, port=6379.
1:M 11 Sep 00:18:34.350 # 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 11 Sep 00:18:34.350 # Server initialized
1:M 11 Sep 00:18:34.350 # 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 11 Sep 00:18:34.350 # 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 11 Sep 00:18:34.350 * Ready to accept connections
1:signal-handler (1536625117) Received SIGTERM scheduling shutdown...
1:M 11 Sep 00:18:37.375 # User requested shutdown...
1:M 11 Sep 00:18:37.375 * Saving the final RDB snapshot before exiting.
1:M 11 Sep 00:18:37.378 * DB saved on disk
1:M 11 Sep 00:18:37.378 # Redis is now ready to exit, bye bye...

最佳答案

遇到了同样的问题。经过一番挖掘,我们发现它由于不活动而被 systemd 杀死。
运行 systemctl show docker.service命令显示 inactive 和 active 输入时间戳与 redis 服务停止和重新启动的时间相匹配。

InactiveEnterTimestamp=Tue 2021-08-03 22:07:19 AEST
ActiveEnterTimestamp=Wed 2021-08-04 09:30:36 AEST
我们的解决方案只是在 redis 上执行一些事件,使其不会进入非事件状态。

关于docker - Redis 在 docker 容器中无故关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52267111/

相关文章:

python - 如何使用 Python3.7 和 Pipenv 为 Flask 应用程序运行 Docker 容器?

docker - 在 Dockerfile 中为 LABEL 传递一个 ENV 变量

redis - 你如何处理失败的 redis 连接

node.js - 如何从本地主机向我的 docker 容器发送 HTTP 请求?

docker - 在 compose 中取消设置环境变量

python - 如何使用 python pandas 从 docker 容器访问 CSV 文件(位于电脑硬盘中)?

node.js - 无法运行 node-redis-session 库

json - 在服务器端缓存 JSON 对象

node.js - 在 VS 代码调试器中配置设置以运行 docker

docker - 使用 docker 容器作为网关