Skip to content
Snippets Groups Projects
Commit aa9154e0 authored by Rokas Stankunas's avatar Rokas Stankunas
Browse files

Merge branch '14-containerize-application' into 'main'

Containerized application and updated README.md file

Closes #14

See merge request !10
parents 145f7e8f c3b24b10
No related branches found
No related tags found
1 merge request!10Containerized application and updated README.md file
Pipeline #16353 passed
# We're taking the latest Alpine version, because it's the smallest
# and has the least amount of dependencies
FROM alpine:latest
# Set working directory.
WORKDIR /app
# Copy the current directory contents (whole project) into the container at /app
ADD . /app
# Install dependencies
RUN apk update && \
apk add --no-cache nodejs npm && \
npm install;
# Run the app
ENTRYPOINT ["node", "server"]
\ No newline at end of file
......@@ -27,27 +27,16 @@ lists. **Use MongoDB as the database.**
---
## Deployment
The deployment consists of 2 parts: deploying the database and the application.
1. Create a docker compose file:
```yml
services:
mongodb:
image: mongo:latest
container_name: mongodb
ports:
- "27017:27017"
```
2. Start docker compose file
`sudo docker compose up -d`
3. Clone the repository:
In exercise 1, the deployment consisted of 2 parts: deploying the database and the application. However, in exercise 2, the application got containerized, so you can deploy it by following these simple steps:
1. Clone the repository:
`git clone https://gitlab.reutlingen-university.de/gajesh24/cloudcomputing_act1.git`
4. Enter the folder:
2. Enter the folder:
`cd cloudcomputing_act1`
5. Install dependencies:
`npm install`
6. Start server
`node server`
7. Open up website on `http://localhost:3000/`
3. Build the image:
`sudo docker build -t todo-app .`
4. Start docker compose file
`sudo docker compose up -d`
5. Open up website on `http://localhost/`
---
## Authors
......
services:
mongodb:
image: mongo:latest
container_name: mongodb
ports:
- "27017:27017"
todo-app:
image: todo-app
container_name: todo-app
ports:
- "80:3000"
depends_on:
- mongodb
environment:
- MONGO_URI=mongodb://mongodb:27017/todo-app
......@@ -3,7 +3,7 @@ require('dotenv').config();
const connectDB = async () => {
try {
const conn = await mongoose.connect(process.env.MONGO_URI);
const conn = await mongoose.connect(process.env.MONGO_URI || "mongodb://mongodb:27017/todo-app");
console.log(`MongoDB connected: ${conn.connection.host}`);
} catch (err) {
console.error(`Error: ${err.message}`);
......
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