Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
ToDo_App
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michael Handel
ToDo_App
Commits
766de8b0
Commit
766de8b0
authored
2 months ago
by
Michael Handel
Browse files
Options
Downloads
Patches
Plain Diff
Exercise 3 - added flexible Ports and a second container with different port
parent
b3612769
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Dockerfile
+3
-3
3 additions, 3 deletions
Dockerfile
docker-compose.yml
+17
-4
17 additions, 4 deletions
docker-compose.yml
public/index.html
+1
-1
1 addition, 1 deletion
public/index.html
server.js
+1
-1
1 addition, 1 deletion
server.js
with
22 additions
and
9 deletions
Dockerfile
+
3
−
3
View file @
766de8b0
#
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
...
...
This diff is collapsed.
Click to expand it.
docker-compose.yml
+
17
−
4
View file @
766de8b0
services
:
app
:
app
1
:
build
:
context
:
.
dockerfile
:
Dockerfile
ports
:
-
"
300
0
:3000"
#
Expose the app on
port 300
0
-
"
300
1
:3000"
#
Map container port 3000 to host
port 300
1
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
This diff is collapsed.
Click to expand it.
public/index.html
+
1
−
1
View file @
766de8b0
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
server.js
+
1
−
1
View file @
766de8b0
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment