Skip to content
Snippets Groups Projects
Commit 766de8b0 authored by Michael Handel's avatar Michael Handel
Browse files

Exercise 3 - added flexible Ports and a second container with different port

parent b3612769
No related branches found
No related tags found
No related merge requests found
# Use the official Node.js image as the base image
# official Node.js image as the base image
FROM node:18
# Set the working directory inside the container
......@@ -7,13 +7,13 @@ WORKDIR /app
# Copy package.json and package-lock.json to the container
COPY package*.json ./
# Install dependencies
# Install dependencies from packages
RUN npm install
# Copy the rest of the application code to the container
COPY . .
# Expose the application port
# application port
EXPOSE 3000
# Start the application
......
services:
app:
app1:
build:
context: .
dockerfile: Dockerfile
ports:
- "3000:3000" # Expose the app on port 3000
- "3001:3000" # Map container port 3000 to host port 3001
environment:
- PORT=3000
- MONGO_URL=mongodb://db:27017/todo-app # MongoDB connection string
depends_on:
- db
app2:
build:
context: .
dockerfile: Dockerfile
ports:
- "3002:3000" # Map container port 3000 to host port 3002
environment:
- PORT=3000
- MONGO_URL=mongodb://db:27017/todo-app # MongoDB connection string
depends_on:
- db
......@@ -14,9 +27,9 @@ services:
image: mongo:6.0
container_name: mongodb
ports:
- "27017:27017" # Expose MongoDB on port 27017
- "27017:27017"
volumes:
- mongo-data:/data/db # Persist MongoDB data
- mongo-data:/data/db # MongoDB data Volume
volumes:
mongo-data:
\ No newline at end of file
......@@ -15,7 +15,7 @@
<script>
// Base URL for the backend API
const API_URL = 'http://localhost:3000/todos';
const API_URL = `${window.location.origin}/todos`;
let showAll = false; // State to toggle visibility of completed TODOs
// Fetch and display TODO items from the backend
......
......@@ -6,7 +6,7 @@ const path = require('path'); // Import path module for serving static files
// Initialize Express app
const app = express();
const PORT = 3000; // Define the port the server will run on
const PORT = process.env.PORT || 3000; // Define the port the server will run on
// Middleware setup
app.use(express.json()); // Parse incoming JSON requests
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment