node.jsdockernestjs

Dockerized NestJS application only accepts GET request


I made a NestJS application and deployed into AWS lightsail using docker, and faced a weird situation.

I could see that the application runs correctly and I can connect to the application at the external of the container.

However, the weird situation is when I try to send POST request then it hangs up, but not when I try to send GET request. (And I did not happen when I tested it locally.)

Also when I checked the log of the container, I found that nothing happened when the POST request was made.

Here's the API document of my server: (deleted)

Here's the code of my Dockerfile:

# Step 1 Build
FROM node:lts AS builder
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

# Step 2 Application Start
FROM node:lts-alpine
ARG STAGE
WORKDIR /usr/src/app
COPY --from=builder /usr/src/app/dist ./dist
COPY --from=builder /usr/src/app/node_modules ./node_modules
COPY --from=builder /usr/src/app/.env.$STAGE ./.env
ENTRYPOINT ["node", "dist/src/main.js"]

Here's the code of my docker-compose:

version: '3'
services:
  node:
    container_name: backend-dev
    image: dokdo2005/freedea-api:development
    ports:
      - 80:3000
    restart: always
  postgres:
    container_name: postgres-dev
    image: postgres:14-alpine
    ports:
      - 5432:5432
    restart: always
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=freedea
    volumes:
      - postgres-data-dev:/var/lib/postgresql/data
  redis:
    container_name: redis-dev
    image: redis:6.2.4-alpine
    ports:
      - 6379:6379
    restart: always
volumes:
    postgres-data-dev:

Is there anything wrong I made?


Solution

  • The main reason was that the server(backend-dev) always stops when the DB transaction starts, and I changed the base image in Dockerfile from node:lts-alpine to node:lts. Then the problem was solved. It seems that node:lts-alpine image has a compatibility issue with TypeORM and PostgreSQL.