From 519295870664bf954ff6479134c8aab41da5bb75 Mon Sep 17 00:00:00 2001 From: Kally <60466044+kallyas@users.noreply.github.com> Date: Fri, 25 Aug 2023 10:15:56 +0300 Subject: [PATCH] Update Dockerfile --- server/Dockerfile | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/server/Dockerfile b/server/Dockerfile index bffbada..dc9b284 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -1,22 +1,23 @@ -FROM node:16-bullseye-slim +# Use the official Node.js image as the base image +FROM node:lts-alpine -# Create app directory +# Set the working directory in the container WORKDIR /app -# Install app dependencies -COPY package*.json ./ +# Copy package.json and package-lock.json +COPY server/package.json server/package-lock.json ./ -ARG NODE_ENV +# Install dependencies +RUN npm install --production -RUN if [ "$NODE_ENV" == "development" ]; \ - then npm install; \ - else npm install --only=production; \ - fi +# Install MongoDB +RUN apk add --no-cache mongodb-tools -# Bundle app source -COPY . ./ +# Create a directory for MongoDB data and logs +RUN mkdir -p /data/db /var/log/mongodb -ENV PORT 5000 +# Expose the port that your Node.js Express app listens on (e.g., 3000) +EXPOSE 5000 -EXPOSE ${PORT} -CMD [ "node", "src/index.js" ] \ No newline at end of file +# Start MongoDB and your server +CMD mongod --fork --logpath /var/log/mongodb/mongod.log && node src/index.js