From 75b05d82e614e42c361bec2895aab4828118eae9 Mon Sep 17 00:00:00 2001 From: haseebzaki-07 Date: Sat, 12 Oct 2024 18:55:54 +0530 Subject: [PATCH] Update docker-compose --- Dockerfile | 5 +---- backend/Dockerfile | 18 ++++++++++++++++++ docker-compose.yml | 44 ++++++++++++++++++++++++++++++++++++++------ 3 files changed, 57 insertions(+), 10 deletions(-) create mode 100644 backend/Dockerfile diff --git a/Dockerfile b/Dockerfile index 6265fc19..ad0a2cb8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,8 @@ # Step 1: Use an official Nginx image from Docker Hub FROM nginx:alpine -# Step 2: Copy your local files to the Nginx html folder +# Step 2: Copy your local files (frontend) to the Nginx html folder COPY . /usr/share/nginx/html -# Expose port 80 to be able to access the Nginx server -EXPOSE 80 - # Step 3: Start Nginx server CMD ["nginx", "-g", "daemon off;"] diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 00000000..dbeb8a57 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,18 @@ +# Step 1: Use an official Node.js image from Docker Hub +FROM node:14-alpine + +# Step 2: Set working directory in container +WORKDIR /usr/src/app + +# Step 3: Copy package.json and install dependencies +COPY backend/package*.json ./ +RUN npm install + +# Step 4: Copy the backend code to the container +COPY backend/ . + +# Step 5: Expose the backend's port (if your backend runs on port 3000, adjust as needed) +EXPOSE 3000 + +# Step 6: Start the backend server +CMD ["npm", "start"] diff --git a/docker-compose.yml b/docker-compose.yml index 73406695..e569ce17 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,41 @@ -version: '3' services: - web: - image: nginx:alpine - container_name: static-web-app + frontend: + build: + context: . + dockerfile: Dockerfile ports: - - "8080:80" + - "80:80" + depends_on: + - backend + networks: + - app-network + + backend: + build: + context: . + dockerfile: backend/Dockerfile + ports: + - "3000:3000" + networks: + - app-network + environment: + - NODE_ENV=production + - MONGODB_URI=mongodb://mongo:27017/mydatabase + depends_on: + - mongo + + mongo: + image: mongo:latest + ports: + - "27017:27017" volumes: - - .:/usr/share/nginx/html + - mongo_data:/data/db + networks: + - app-network + +networks: + app-network: + driver: bridge + +volumes: + mongo_data: \ No newline at end of file