Dockerfile for npm start
npm start is frequently used command to run a node application like: Reactjs. Use can use the below Dockerfile for running node applications with Docker.
Create a file named Dockerfile in the project base directory and add the below code.
FROM node:16-alpine RUN mkdir /app WORKDIR /app COPY package.json /app RUN npm install COPY . /app EXPOSE 3000 CMD ["npm", "start"]
Make sure to change the value of EXPOSE to the port application runs on. Also assuming that your application runs with
npm start command.
Now, build a docker image for your application. In a terminal, run the following command from the application base directory.
docker build -t image-name .
Once the image build is completed, you can run your application.
sudo docker run -it -d image-name