尝试使用 NestJS、TypeORM、Docker、Postgres 进行迁移时出现 ECONNREFUSED 错误
ECONNREFUSED error trying migration with NestJS, TypeORM, Docker, Postgres
在 Ubuntu 20.4
上使用 NestJS、docker-compose 和 Postgres
尝试使用此应用进行我的第一次数据库迁移:
npx typeorm migration:create -n mushroomRefactor
npm run build
npx typeorm migration:run
docker-撰写:
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',
},
};
Docker 文件:
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 }
检查你设置的端口,不一样
在 Ubuntu 20.4
上使用 NestJS、docker-compose 和 Postgres尝试使用此应用进行我的第一次数据库迁移:
npx typeorm migration:create -n mushroomRefactor
npm run build
npx typeorm migration:run
docker-撰写:
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',
},
};
Docker 文件:
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 }
检查你设置的端口,不一样