Deploying a NestJS app with Postgres

I have created a simple Restful CRUD app with NestJS boiler plate template and serving the app on Port 8080. I also have a Postgres instance running in a docker container. I am now trying to deploy this app on Fly.io but I am having a lot of trouble and confusing in doing so.

Below is my docker-compose.yml which is pretty straightforward:

version: '3.8'
services:
  api:
    container_name: todoapp-api
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - 3333:3333
    depends_on:
      postgresdb:
        condition: service_healthy
    restart: on-failure

  postgres:
    image: postgres:13
    container_name: postgres_db
    ports:
      - '5433:5432'
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready', '-d', 'mydb']
      interval: 10s
      timeout: 5s
      retries: 5
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: 123
      POSTGRES_DB: nest
    volumes:
      - ./data:/var/lib/postgresql/data

volumes:
  postgres:

And I have this Dockerfile that I created as well:

FROM node:18
WORKDIR /app
COPY . .
RUN npm install
EXPOSE 3333

CMD [  "yarn", "start:migrate:serve" ]

The yarn start:migrate:serve command is simply: "start:migrate:serve": "prisma migrate deploy && yarn start:dev"

I would appreciate some insight as to what I can do to get this app running.

The simplest path forward is to rename your Dockerfile, and then run fly launch; making sure you agree to letting it create a PostgresQL machine for you.

I did that. The Postgres instance is running but the NestJS one crashes. Here are the logs I am getting too for the NestJS app.

In your NestJS application, do you have a call to app.listen? Can you change that call to specify 0.0.0.0? See Why does specifying the URL as '0.0.0.0' allow my NestJS-fastify app to deploy to Heroku? - Stack Overflow

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.