I am new to docker and trying to move my MERRN stack application to AWS. I want to dockerize it before I move it. However, when I followed this online tutorial at Medium - Docker with MERN stack I get to the part with starting up my docker image with docker run -p 5000:5000 -d backend
and I get an error in VS code. I am not sure what this error means but I theorize it has to do with my folder management.
I will attach a snippet of my folder structure as well as the docker file I used. So my main problem is I am trying to get everything setup but this issue is hindering my progress. So any help would be appreciated. Thanks
DockerFile:
FROM node:10.19.0
# Create app directory
WORKDIR /usr/src/app
# A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json ./
# Bundle app source
COPY . .
# Install app dependencies
RUN npm install
EXPOSE 5000
CMD [ "npm", "start" ]
Error:
> exodus@1.0.0 start /usr/src/app
> node server
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module './routes/api/Email'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/usr/src/app/server.js:24:19)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! exodus@1.0.0 start: `node server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the exodus@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-10-28T20_13_53_160Z-debug.log
Search...
Stick to bottom
Your Dockerfile seems ok and your project structure, too. I assume that the docker image is faulty for some reason and missing the files.
Can you try to build the image again? Is the COPY step executed correctly?
// Make sure to execute this in the project root.
docker build -t backend .
If the error persists, log into the docker container using bash or sh and try to manually start the node server with npm start
:
docker run -p 5000:5000 -d backend /bin/bash
or
docker run -p 5000:5000 -d backend /bin/sh
Logging into the docker container will also help to investigate if eg some files were not transferred.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.