1
0
Fork 0
mirror of https://github.com/docker/awesome-compose.git synced 2025-04-25 18:28:07 +02:00
awesome-compose/react-express-mongodb/backend
Thoshinny B c2071c0e14
Updated README.md at /react-express-mongodb /backend/
Enhanced Dockerfile snippet in README.md

The Dockerfile snippet in the README.md file required adjustments to align it more closely with the actual Dockerfiles in both the Backend and Frontend directories. I've made a few improvements to ensure clarity and accuracy.

Original Snippet in Repository:

FROM node:13.13.0-stretch-slim
# Argument passed from docker-compose.yaml file
ARG NODE_PORT
# Echo the argument to check if it's loaded correctly
RUN echo "Argument port is: $NODE_PORT"
# Create app directory
WORKDIR /usr/src/app
# Copy entire content
COPY . .
# Install app dependencies
RUN npm install
# My app binds to port NODE_PORT; use the EXPOSE instruction for Docker daemon mapping:
EXPOSE ${NODE_PORT}
CMD npm run dev

Modified Snippet:

FROM node:13.13.0-stretch-slim
# Argument passed from docker-compose.yaml file
ARG NODE_PORT
# Echo the argument to check if it's loaded correctly
RUN echo "Argument port is: $NODE_PORT"
# Create app directory
WORKDIR /usr/src/app
# Copy dependency definitions first for better Docker caching
COPY package.json /usr/src/app
# Install app dependencies
RUN npm install
# Copy the entire application code
COPY . /usr/src/app
# My app binds to port NODE_PORT; use the EXPOSE instruction for Docker daemon mapping:
EXPOSE ${NODE_PORT}
CMD npm run dev


These changes ensure consistency and readability.

Signed-off-by: Thoshinny B <69354714+Thoshinny-cyber@users.noreply.github.com>
2023-12-08 16:58:10 +05:30
..
config Fixed typo in message. (#132) 2021-05-21 17:44:22 +01:00
db Arm64 and check Compose v2 support (#177) 2021-11-08 11:41:35 +01:00
logs react-express-mongodb: lint sources 2020-05-13 11:33:48 +02:00
models/todos react-express-mongodb: lint sources 2020-05-13 11:33:48 +02:00
routes react-express-mongodb: lint sources 2020-05-13 11:33:48 +02:00
utils/helpers react-express-mongodb: lint sources 2020-05-13 11:33:48 +02:00
.dockerignore react-express-mongodb: clean frontend code 2020-05-13 11:33:48 +02:00
Dockerfile add configuration to use react-express-mongo sample with Docker Dev Environments feature (#271) 2022-07-13 10:15:53 +02:00
package-lock.json Fix security issues (#244) 2022-05-16 21:20:20 +02:00
package.json fix issue in validor dependency in the backend of react-express-mongodb sample (#175) 2021-11-04 14:58:45 +01:00
README.md Updated README.md at /react-express-mongodb /backend/ 2023-12-08 16:58:10 +05:30
server.js react-express-mongodb: lint sources 2020-05-13 11:33:48 +02:00

Snippet of backend(Node.js)DockerFile

You will find this DockerFile file in the root directory of the project.

FROM node:13.13.0-stretch-slim
#Argument that is passed from docker-compose.yaml file
ARG NODE_PORT
#Echo the argument to check passed argument loaded here correctly
RUN echo "Argument port is : $NODE_PORT"
# Create app directory
WORKDIR /usr/src/app
# Copy dependency definitions
COPY package.json /usr/src/app
# Install app dependencies
RUN npm install
# Get all the code needed to run the app
COPY . /usr/src/app
#In my case my app binds to port NODE_PORT so you'll use the EXPOSE instruction to have it mapped by the docker daemon:
EXPOSE ${NODE_PORT}
CMD npm run dev
Explanation of backend(Node.js) DockerFile
  • The first line tells Docker to use another Node image from the DockerHub. Were using the official Docker image for Node.js and its version 10 image.

  • On second line we declare argument NODE_PORT which we will pass it from docker-compose.

  • On third line we log to check argument is successfully read

  • On fourth line we set a working directory ,where the app code will be set to present inside the Docker container.

  • On fifth line, we are copying our dependency file (i,e package.json) into container working directory which was set on line four.

  • On sixth line, we run npm install for dependencies installation in container.

  • On line seven, we are copying/bundling our code working directory into container working directory which was set on line four.

  • On Line eight, we setup the port, that Docker will expose when the container is running. In our case it is the port which we define inside .env file, read it from docker-compose then passed as a argument to the (backend)DockerFile.

  • And at last, we tell docker to execute our app inside the container by using node to run `npm run dev. It is the command which I registered in package.json in script section.

📋 Note: For development purpose I used __nodemon__ , If you need to deploy at production you should change CMD from __npm run dev__ to __npm start__.