【发布时间】:2020-09-20 07:52:48
【问题描述】:
您好,我不知道还有什么办法可以解决此错误:
ci-api | Error: getaddrinfo ENOTFOUND ${DB_HOST}
ci-api | at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26) {
ci-api | errno: 'ENOTFOUND',
ci-api | code: 'ENOTFOUND',
ci-api | syscall: 'getaddrinfo',
ci-api | hostname: '${DB_HOST}'
ci-api | }
我有一个带有以下变量的.env 文件:
.env文件:
SERVER_PORT=4000
DB_HOST=db-pg
DB_PORT=5432
DB_USER=spirit
DB_PASS=api
DB_NAME=emasa_ci
DockerFile:
#building code
FROM node:lts-alpine
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.7.3/wait /wait
RUN chmod +x /wait
RUN mkdir -p /home/node/api && chown -R node:node /home/node/api
WORKDIR /home/node/api
COPY ormconfig.json .env package.json yarn.* ./
USER node
RUN yarn
COPY --chown=node:node . .
EXPOSE 4000
**My `docker-compose`:**
version: '3.7'
services:
db-pg:
image: postgres:12
container_name: db-pg
ports:
- '${DB_PORT}:5432'
environment:
ALLOW_EMPTY_PASSWORD: 'no'
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASS}
POSTGRES_DB: ${DB_NAME}
volumes:
- ci-postgres-data:/data
ci-api:
build: .
container_name: ci-api
volumes:
- .:/home/node/api
ports:
- '${SERVER_PORT}:${SERVER_PORT}'
depends_on:
- db-pg
command: sh -c "/wait && yarn dev"
environment:
WAIT_HOSTS: db-pg:5432
logging:
driver: 'json-file'
options:
max-size: '10m'
max-file: '5'
volumes:
ci-postgres-data:
还有,这是我的ORM CONFIG:
{
"type": "postgres",
"host": "${DB_HOST}",
"port": "${DB_PORT}",
"username": "${DB_USER}",
"password": "${DB_PASS}",
"database": "${DB_NAME}",
"synchronize": true,
"logging": false,
"entities": ["dist/src/entity/**/*.js"],
"migrations": ["dist/src/migration/**/*.js"],
"subscribers": ["dist/src/subscriber/**/*.js"],
"cli": {
"entitiesDir": "dist/src/entity",
"migrationsDir": "dist/src/migration",
"subscribersDir": "dist/src/subscriber"
}
}
我无法想象这个错误的原因,我基本上在我的 Postgres 启动后添加了一个脚本让节点启动,其中 db-pg 是我的 Postgres 图像名称。
我无法想象出了什么问题,有人可以帮我解决这个问题吗?
P.S.:我用typescript/typeorm
【问题讨论】:
标签: node.js postgresql docker typeorm