【问题标题】:Error when running database migrations with NestJS, TypeORM and Docker使用 NestJS、TypeORM 和 Docker 运行数据库迁移时出错
【发布时间】:2022-01-03 00:22:18
【问题描述】:

在 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: 'db',
  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: getaddrinfo EAI_AGAIN db at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26) { errno: -3001, code: 'EAI_AGAIN', syscall: 'getaddrinfo', hostname: 'db' }

【问题讨论】:

    标签: postgresql docker-compose migration nestjs typeorm


    【解决方案1】:

    在您的 NestJS 应用程序中使用端口 5432,因为 5423 是暴露给主机的端口。容器之间共享的端口仍然是5432

    【讨论】:

      猜你喜欢
      • 2022-01-12
      • 2020-12-14
      • 2020-12-29
      • 2023-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-29
      相关资源
      最近更新 更多