docker上的redis由于多个错误而无法运行

q3qa4bjr  于 2021-06-09  发布在  Redis
关注(0)|答案(1)|浏览(299)

我一直试图连接一个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. (/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配置文件的这个错误,但是如何在docker图像中解决它,这没有很好的解释。连接没有问题,但问题在于redis的conf。我可以用dns/ip从其他容器ping到那个容器。我认为,如果错误的最后一部分,其中*:6379不能听到,如果这和conf文件是编辑,应用程序将正常工作。
3b6akqbq

3b6akqbq1#

您正在连接到 redis 来自另一个容器的容器 0.0.0.0:6379 地址。使用docker服务名称 redis:6379 或者主机的ip地址 redis 到主机的容器端口。

相关问题