2

Using NestJS, docker-compose and Postgres on Ubuntu 20.4

Trying my first database migration with this app:

npx typeorm migration:create -n mushroomRefactor

npm run build

npx typeorm migration:run

docker-compose:

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" ]

But it is returning:

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' }

1 Answer 1

3

use the port 5432 in your NestJS app, cause the 5423 is the port which exposed to host machine. The port that shared between container is still 5432

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.