Postgres “Password Authentication Failed” trying to run npm typeorm migrations

  • On Windows WSL

I have a Node TypeScript application that runs on my local machine but also connects to a local Postgres database that gets created in Docker. So the DB is in Docker but the app is on my local machine.

when I npm run start:dev it will init the db with the docker-compose.yaml, then use npm typeorm to run the migrations, then nx to serve the application.

  1. My init-db script is successfully spinning up the Docker Postgres instance and creates the db

  2. when trying to run the migrations I’m getting the following error:

Error during migration run:
error: password authentication failed for user "postgres"
...........
{
  length: 104,
  severity: 'FATAL',
  code: '28P01',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'auth.c',
  line: '321',
  routine: 'auth_failed'
}

all the passwords and configurations are correct in my env files

got the container IP for the postgres instance and tried to connect to it directly through terminal psql command, and it would time out. the only way to get into the db through psql was to actually go to the terminal within the Docker application inside the container.

i think the most obvious solution is to Dockerize all the things but that can’t be done right now with the team I’m working on. All my other team members are on Mac and have no issues, the only difference in our setups is that I’m on Windows WSL.

Is there perhaps some kind of permissions configuration I need to do in Docker to allow local applications outside of the container to connect??

// docker-compose.yaml
version: '3.8'

services:
  postgres:
    container_name: postgres
    image: postgres:15
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: secret
    volumes:
      - ./init-database.sh:/docker-entrypoint-initdb.d/init-database.sh
    ports:
      - '5432:5432'
// .env file
....
# LOCAL DB
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=secret
DB_NAME=tracker
// ormconfig.ts
import { DataSource } from 'typeorm';
import { config } from 'dotenv';

config();

export default new DataSource({
  type: 'postgres',
  host: process.env.DB_HOST || 'localhost',
  port: Number(process.env.DB_PORT) || 5432,
  username: process.env.DB_USER || 'postgres',
  password: process.env.DB_PASSWORD || 'secret',
  database: process.env.DB_NAME || 'tracker',
  entities: [process.env.ENV === 'local' ? 'dist/**/entities/**/*.js' : 'src/**/entities/**/*.js'],
  migrations: [process.env.ENV === 'local' ? 'dist/**/migrations/**/*.js' : 'src/**/migrations/**/*.js'],
  synchronize: false,
  ssl: process.env.ENV !== 'local',
});
// package.json scripts
// running npm run start:dev
"scripts": {
    "start:dev": "docker-compose up -d && npm run migration:run && nx run-many -t serve",
    "typeorm": "npx typeorm-ts-node-commonjs",
    "migration:run": "nx build redacted-backend && npm run typeorm -- --dataSource=apps/redacted-backend/ormconfig.ts migration:run",
  },
  • npm installed all deps
  • npm, node, nvm all up to date
  • clearing out docker containers between attempts
  • tried using localhost and 127.0.0.1 and postgresdb and <container-ip> for the connection string
  • tried using “password” everywhere for the postgres_password instead of “secret” since “password” is the default
  • uninstalled and reinstalled postgres in WSL terminal
  • manually set postgres password thru psql in the Docker terminal

New contributor

Davis Arnoodle is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật