0

I keep getting errors that my modules don't exist when I'm running nodemon inside Docker and I save the node files. It takes a couple of saves before it throws the error. I have the volumes mounted like how the answers suggested here but I'm still getting the error and I'm not too sure what's causing it.

Here is my docker-compose.yml file.

version: "3.7"
services:
  api:
    container_name: api
    build:
      context: ./api
      target: development
    restart: on-failure
    ports:
      - "3000:3000"
      - "9229:9229"
    volumes:
      - "./api:/home/node/app"
      - "node_modules:/home/node/app/node_modules"
    depends_on:
      - db
    networks:
      - backend
  db:
    container_name: db
    command: mongod --noauth --smallfiles
    image: mongo
    restart: on-failure
    volumes:
      - "mongo-data:/data/db"
      - "./scripts:/scripts"
      - "./data:/data/"
    ports:
      - "27017:27017"
    networks: 
      - backend
networks:
  backend:
    driver: bridge
volumes:
  mongo-data:
  node_modules:

Here is my docker file:

# Ger current Node Alpine Linux image.
FROM node:alpine AS base
# Expose port 3000 for node.
EXPOSE 3000
# Set working directory.
WORKDIR /home/node/app
# Copy project content.
COPY package*.json ./

# Development environment.
FROM base AS development
# Set environment of node to development to trigger flag.
ENV NODE_ENV=development
# Express flag.
ENV DEBUG=app
# Run NPM install.
RUN npm install
# Copy source code.
COPY . /home/node/app
# Run the app.
CMD [ "npm", "start" ]

# Production environment.
FROM base AS production
# Set environment of node to production to trigger flag.
ENV NODE_ENV=production
# Run NPM install.
RUN npm install --only=production --no-optional && npm cache clean --force
# Copy source code.
COPY . /home/node/app
# Set user to node for better security.
USER node
# Run the app.
CMD [ "npm", "run", "start:prod" ]
yaserso
  • 2,638
  • 5
  • 41
  • 73

1 Answers1

0

Turns out I didn't put my .dockerignore in the proper folder. You're supposed to put it in the context folder.

yaserso
  • 2,638
  • 5
  • 41
  • 73