【问题标题】:ECONNREFUSED error trying migration with NestJS, TypeORM, Docker, Postgres尝试使用 NestJS、TypeORM、Docker、Postgres 进行迁移时出现 ECONNREFUSED 错误
【发布时间】:2022-01-12 21:59:32
【问题描述】:

在 Ubuntu 20.4 上使用 NestJS、docker-compose 和 Postgres

尝试使用此应用程序进行我的第一次数据库迁移:

npx typeorm migration:create -n mushroomRefactor

npm run build

npx typeorm migration:run

码头工人撰写:

version: "3"

services: 
  db:
    image: postgres
    restart: always
    volumes:
      - mushrooms-psql:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    environment: 
      POSTGRES_PASSWORD: pass123
  
volumes:
  mushrooms-psql:

ormconfig.js:

module.exports = {
  type: 'postgres',
  host: 'localhost',
  port: 5423,
  username: 'postgres',
  password: 'pass123',
  database: 'postgres',
  entities: ['dist/**/*.entity.js'],
  migrations: ['dist/migrations/*.js'],
  cli: {
    migrationsDir: 'src/migrations',
  },
};

Dockerfile:

FROM node:16

# install app dependencies 
# use wildcard * to install package.json and package-lock.json
COPY package*.json ./

RUN npm install

# bundle app source
COPY . . 

EXPOSE 8080

RUN npm run build

# entry file to run the app
CMD [ "node", "dist/main" ]

但它正在返回: Error during migration run: Error: connect ECONNREFUSED 127.0.0.1:5423 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1146:16) { errno: -111, code: 'ECONNREFUSED', syscall: 'connect', address: '127.0.0.1', port: 5423 }

【问题讨论】:

  • 你的 docker compose 正在运行,对吧? docker-compose ps?
  • 是的! world-of-mushrooms_db_1 docker-entrypoint.sh postgres Up 0.0.0.0:5432/tcp,:::5432->5432/tcp
  • 你是在你的机器上运行这个命令,而不是在 docker 容器中,对吧?
  • 是的,我相信...我不在容器的外壳内。如果您知道,我一直在关注 NestJS 网站上的教程。

标签: postgresql docker-compose nestjs typeorm


【解决方案1】:

检查你设置的端口,它不一样

【讨论】:

  • 啊!发现得好。谢谢。
猜你喜欢
  • 2020-01-03
  • 2021-07-29
  • 2022-01-03
  • 1970-01-01
  • 1970-01-01
  • 2015-07-10
  • 1970-01-01
  • 2023-01-07
  • 2021-08-11
相关资源
最近更新 更多