docker-compose up –build cannor find module

  docker, node.js, npm

When I start my container (node web app), the docker build it’s fine but when I run my container this issues appear

The issue:
[email protected]:/home/daramog/ezops-test-matheus-morozetti# docker-compose up
Recreating ezops-test-matheus-morozetti_web_1 … done
Attaching to ezops-test-matheus-morozetti_web_1
web_1 | node:internal/modules/cjs/loader:944
web_1 | throw err;
web_1 | ^
web_1 |
web_1 | Error: Cannot find module ‘/app/server.js’
web_1 | at Function.Module._resolveFilename (node:internal/modules/cjs/loader:941:15)
web_1 | at Function.Module._load (node:internal/modules/cjs/loader:774:27)
web_1 | at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
web_1 | at node:internal/main/run_main_module:17:47 {
web_1 | code: ‘MODULE_NOT_FOUND’,
web_1 | requireStack: []
web_1 | }
ezops-test-matheus-morozetti_web_1 exited with code 1

My Dockerfile: FROM node:alpine as builder

WORKDIR ‘/src’

COPY package*.json ./
RUN npm set strict-ssl false
RUN npm install

COPY . ..
RUN node ./server.js

EXPOSE 8080

CMD ["node", "server.js"]

My dockerfile.dev

FROM node:alpine

WORkDIR /src

COPY ["package.json","package-lock.json","/"]
RUN npm install

COPY . .

CMD ["npm", "start"]

My docker-compose

version: ‘3’
services:
web:
build:
context: .
dockerfile: Dockerfile
ports:
– "3001:3001"
volumes:
– .:/src
command: ["node", "server.js"]

Source: Docker Questions

LEAVE A COMMENT