This repository contains the project for the Cloud Computing course at the Technical University of Munich (TUM). The project demonstrates the use of Docker and Docker Compose to build, deploy, and manage microservices in a cloud environment.
The project is organized into the following directories:
/my_project
├── api
│ └── books
│ ├── get
│ │ ├── main.go
│ │ └── Dockerfile
│ ├── post
│ │ ├── main.go
│ │ └── Dockerfile
│ ├── put
│ │ ├── main.go
│ │ └── Dockerfile
│ └── delete
│ ├── main.go
│ └── Dockerfile
├── web
│ ├── main.go
│ ├── Dockerfile
│ ├── views
│ │ ├── index.html
│ │ ├── authors.html
│ │ ├── years.html
│ │ └── search-bar.html
│ └── css
│ └── styles.css
├── nginx
│ └── nginx.conf
├── docker-compose.yml
├── go.mod
└── go.sum
The NGINX service acts as a reverse proxy, routing traffic to the appropriate microservice based on the HTTP request method.
The Web Service serves the web application, providing HTML pages for the user interface.
Handles HTTP GET requests to retrieve book information.
Handles HTTP POST requests to create new book entries.
Handles HTTP PUT requests to update existing book entries.
Handles HTTP DELETE requests to remove book entries.
A MongoDB instance is used to store book information.
- Docker
- Docker Compose
- Clone the Repository
git clone <repository-url>
cd my_project
- Build and Start the Containers
docker-compose up --build
This command will build the Docker images for each service and start the containers.
- Access the Application
- NGINX: http://localhost
- Web Service: http://localhost
- API Endpoints:
GET /api/books
POST /api/books
PUT /api/books
DELETE /api/books/:id
You can use tools like curl
or Postman to test the API endpoints.
Example using curl
to test the GET endpoint:
curl -X GET http://localhost/api/books
The NGINX configuration file is located at nginx/nginx.conf
and routes traffic based on the request methods.
events {}
http {
server {
listen 80;
location /api/books {
if ($request_method = GET) {
proxy_pass http://get_service:80;
}
if ($request_method = POST) {
proxy_pass http://post_service:80;
}
if ($request_method = PUT) {
proxy_pass http://put_service:80;
}
if ($request_method = DELETE) {
proxy_pass http://delete_service:80;
}
}
location / {
proxy_pass http://web_service:80;
}
}
}
Each service connects to MongoDB using the DATABASE_URI
environment variable, which is set in the docker-compose.yml
file:
environment:
- DATABASE_URI=mongodb://mongodb:27017
For any inquiries, please contact the course instructor or the project maintainer.