0

I am trying to create a Nest.js + PostgreSQL with Prisma ORM Docker development environment for an existing project. I am using Docker Desktop app. Here is my Dockerfile:

FROM node:16.15-alpine3.15 AS builder

# Create app directory
WORKDIR /app

# A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json ./
COPY prisma ./prisma/

# Install app dependencies
RUN npm install
RUN npm install --only=dev

COPY . .

RUN npm run build

EXPOSE 3000
CMD [ "npm", "run", "start:dev" ]

And Here is my docker-compose.yaml:

version: "3.8"
services:
  db:
    image: postgres
    container_name: local_pgdb
    restart: always
    expose:
      - "5432"
    ports:
      - "54321:5432"
    volumes:
      - "pg_data:/var/lib/postgresql"
      - "pg_log:/var/log/postgresql"
      - "pg_config:/etc/postgresql"
      - ./docker-config/db:/docker-entrypoint-initdb.d/
    env_file:
      - ./docker-config/db/postgres.env
  pgadmin:
    image: dpage/pgadmin4
    container_name: pgadmin4_container
    restart: always
    expose:
      - "80"
    ports:
      - "5050:80"
    volumes:
      - pgadmin_data:/var/lib/pgadmin
    env_file:
      - ./docker-config/pgadmin/pgadmin.env
    depends_on:
      - db
  contents_api:
    build:
      context: ./
      dockerfile: Dockerfile.local
    container_name: jccme-dp-contents-api
    expose:
      - "3000"
    ports:
      - "3000:3000"
    volumes:
      - ./:/app
      - storage:/app/storage
    stdin_open: true
    tty: true
    depends_on:
      - db
volumes:
  pg_data:
    driver: local
  pg_log:
    driver: local
  pg_config:
    driver: local
  pgadmin_data:
    driver: local
  storage:
    driver: local

Now when I try docker-compose up, then the node_modules folder and dist folder becomes empty. As a result I get a lot of errors of "module not found". Also eslint service cannot start because of empty node_modules folder.

I have tried both VSCode and WebStorm and both gave errors.

Can anyone tell me what am I doing wrong?

LazyOne
  • 158,824
  • 45
  • 388
  • 391
  • Is your repository public? If yes, could you share the repository link so that I could try to reproduce this locally? – Nurul Sundarani Jul 26 '22 at 06:46
  • Your `volumes:` are hiding absolutely everything the Dockerfile does, including the `RUN npm install` step. I'd recommend deleting the first line there (mounting the dedicated storage volume makes sense) and use the code built into the image. For actual development, use Node without Docker, possibly configuring your application to point at the Docker-hosted databases. This is probably the same problem as [Add a volume to Docker, but exclude a sub-folder](https://stackoverflow.com/questions/29181032/add-a-volume-to-docker-but-exclude-a-sub-folder). – David Maze Jul 26 '22 at 09:28

0 Answers0