【发布时间】:2020-08-07 00:44:08
【问题描述】:
我正在 docker 容器中运行 node.js 应用程序。这是我的 docker-compose 文件 -
version: '3.7'
services:
notification-app:
container_name: ${CONTAINER_NAME}
build:
context: ./
dockerfile: ./Dockerfile
args:
- APP_ENV=${APP_ENV}
ports:
- ${EXPORTED_PORT}:${APP_PORT}
environment:
- REDIS_HOST=${REDIS_HOST}
- REDIS_PORT=${REDIS_PORT}
这是我的 .env 文件 -
CONTAINER_NAME=sheba_socket
APP_ENV=development
APP_PORT=3000
EXPORTED_PORT=3000
REDIS_HOST=localhost
REDIS_PORT=6379
我在本地运行 REDIS SERVER(没有容器,直接在机器上)。 当我构建并运行这个容器时,我发现了这个错误。
[ioredis] Unhandled error event: Error: getaddrinfo ENOTFOUND redis
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:64:26)
我认为,问题出在 REDIS_HOST=localhost。 我不确定如何定义 redis 主机。
【问题讨论】: