Deploy multi-container NestJS/Postgres application

Hi!

I have relatively simple application written in Nest JS and using Postgres as DB.

All that is containerized with Docker, i have two Dockerfile’s (dev and prod). Also docker-compose file for managing multiple containers. I was following this article to figure out how to deploy my service with docker-compose and Koyeb.

It worked, but partially, looks like the DB services are starting, but the Nest application not :sweat_smile: This is a bit unexpected.

Here are my files

Dockerfile.koyeb:

FROM koyeb/docker-compose

COPY . /app

Dockerfile.prod:

FROM node:22-alpine as build

# Working directory inside the container
WORKDIR /code

# Copy package.json and package-lock.json
COPY package*.json ./
COPY tsconfig.json ./

# Install dependencies
RUN npm install

# Copy the application code
COPY . .

# Build the application
RUN npm run build

# Production Stage
FROM node:22-alpine AS production

# Working directory inside the container
WORKDIR /app

COPY --from=build /code/dist ./dist
COPY --from=build /code/node_modules ./node_modules
COPY package*.json ./

EXPOSE 8080

# Start the application
CMD ["npm", "run", "start:prod"]

docker-compose.yml

services:
  # Development service
  blogify-dev:
    container_name: blogify-api-dev
    build:
      context: .
      dockerfile: Dockerfile.dev
    env_file:
      - .env.development
    ports:
      - "3002:3000"
    volumes:
      - .:/code
      - /app/node_modules
    depends_on:
      - db
    profiles:
      - dev

  # Production service
  blogify-prod:
    container_name: blogify-api-prod
    build:
      context: .
      dockerfile: Dockerfile.prod
    env_file:
      - .env.production
    ports:
      - "8080:8080"
    restart: always
    volumes:
      - .:/app
    depends_on:
      - db
    profiles:
      - prod

  # Database service (PostgreSQL)
  db:
    image: postgres:17-alpine
    container_name: blogify-db
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=postgres
    ports:
      - "5432:5432"
    volumes:
      - db-data:/var/lib/postgresql/data

  # pgAdmin service
  pgadmin:
    image: dpage/pgadmin4
    container_name: blogify-pgadmin4
    environment:
      - PGADMIN_DEFAULT_EMAIL=admin@example.com
      - PGADMIN_DEFAULT_PASSWORD=admin
    ports:
      - '5050:80'
    depends_on:
      - db

volumes:
      db-data:

All files are in root directory. And in the screenshot you can see my settings inside Koyeb service

Hi @VAhe_Abovyan, if you have only 1 service there is no need to use docker-compose. You can try directly Dockerfile.<env> to deploy your Nest JS app.