docker - 由于多个错误,docker 上的 Redis 无法运行
问题描述
我一直在尝试将 redis 容器连接到我的节点应用程序容器,但我收到了以下错误。在报告问题之前请先了解一下。
docker-compose
version: "3"
services:
vote:
build: ./voting/.
ports:
- "3000:3000"
networks:
- front-tier
- back-tier
result:
build: ./result/.
ports:
- "3011:3011"
networks:
- front-tier
- back-tier
worker:
build:
context: ./service_worker/.
depends_on:
- "redis"
- "db"
networks:
- back-tier
redis:
image: redis:alpine
container_name: redis
ports: ["6379"]
networks:
- back-tier
db:
image: mongo:latest
container_name: db
networks:
- back-tier
volumes:
db-data:
networks:
front-tier:
back-tier:
在docker-compose up
vote_1 | the app is running
vote_1 | events.js:292
vote_1 | throw er; // Unhandled 'error' event
vote_1 | ^
vote_1 |
vote_1 | Error: Redis connection to 0.0.0.0:6379 failed - connect ECONNREFUSED 0.0.0.0:6379
vote_1 | at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
vote_1 | Emitted 'error' event on RedisClient instance at:
vote_1 | at RedisClient.on_error (/usr/src/app/node_modules/redis/index.js:341:14)
vote_1 | at Socket.<anonymous> (/usr/src/app/node_modules/redis/index.js:222:14)
vote_1 | at Socket.emit (events.js:315:20)
vote_1 | at emitErrorNT (internal/streams/destroy.js:92:8)
vote_1 | at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
vote_1 | at processTicksAndRejections (internal/process/task_queues.js:84:21) {
vote_1 | errno: 'ECONNREFUSED',
vote_1 | code: 'ECONNREFUSED',
vote_1 | syscall: 'connect',
vote_1 | address: '0.0.0.0',
vote_1 | port: 6379
vote_1 | }
在docker logs redis
1:C 17 Oct 2020 07:36:16.705 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 17 Oct 2020 07:36:16.706 # Redis version=6.0.8, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 17 Oct 2020 07:36:16.706 # 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 17 Oct 2020 07:36:16.708 * Running mode=standalone, port=6379.
1:M 17 Oct 2020 07:36:16.708 # Server initialized
1:M 17 Oct 2020 07:36:16.708 # 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 17 Oct 2020 07:36:16.709 * Ready to accept connections
当我尝试docker exec -ti redis redis-server
13:C 17 Oct 2020 07:42:16.608 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
13:C 17 Oct 2020 07:42:16.608 # Redis version=6.0.8, bits=64, commit=00000000, modified=0, pid=13, just started
13:C 17 Oct 2020 07:42:16.608 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
13:M 17 Oct 2020 07:42:16.608 # Could not create server TCP listening socket *:6379: bind: Address in use
现在我认为这里有几个地方,我已经看到了 redis-config 文件的这个错误,但是如何在 docker 映像中解决它,这没有得到很好的解释。连接没有问题,但问题在于redis的conf。我可以使用 dns/ip 从其他容器 ping 到该容器。我认为如果无法听到 *:6379 的错误的最后一部分,如果这个和 conf 文件被编辑,该应用程序将正常工作。
解决方案
您正在从另一个具有地址的容器连接到redis
容器。如果要将容器端口暴露给主机,0.0.0.0:6379
请使用 docker 服务名称或主机的 ip。redis:6379
redis
推荐阅读
- python - 计算 TensorFlow 学习标签的问题
- pyopencl - 创建 PyOpenCl 上下文会导致以后的访问冲突
- image - 在 wordpress 中上传和裁剪图像并从前端添加文本
- typescript - 我怎样才能做一个`部分
` 但仅适用于可为空的字段? - ios - 如何在 Twilio 应用程序中处理语音和视频的 CXProviderDelegate 函数?
- c# - 如何为事件分配按钮值
- amcharts - 如何在 amcharts 系列中包含自定义值以进行计算
- c# - 什么会导致此事件停止被调用?
- java - 如何通过java在windows上实现PocketSphinx
- python - 如何修复“pandas.core.common”没有属性“AbstractMethodError”?