I am sorry for my very newbie question, but I am having a terrible day figuring out this error, I have an Express app and I am trying to run it in docker compose. I\'ve used thi
If your Dockerfile
and package.json
files are correct and still have the issue:
Make sure you've rebuilt your container images.
Try
docker-compose down -v
before starting the containers again with docker-compose up
.
This removes all volumes.
I also had the same issue when I run docker-compose up
.
Issue resolved by running docker-compose up --build
instead of docker-compose up
.
You need to install the dependencies in the container, which is missing from your Dockerfile.
The common way is to create a Dockerfile that is already aware of your application, and make it copy your package.json
file and perform an npm install
.
This allows your container to find all your code dependencies when you later run your application.
See and example here: https://nodejs.org/en/docs/guides/nodejs-docker-webapp/
The sample Dockerfile
:
FROM node:boron
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install
# Bundle app source
COPY . /usr/src/app
EXPOSE 8080
CMD [ "npm", "start" ]
You may need to adapt paths for the COPY
command, of course.