Skip to content

Latest commit

 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Job-Challenge

Project Structure

Job-ch/
├── api/
│   ├── Dockerfile
│   └── app.py
├── nginx/
│   └── default.conf
├── compose.yml
├── index.html
├── .env
├── .gitignore
└── README.md

Additional Tinkering

Instead of using any CSP, I self-hosted this on my own infrastructure using a Raspberry Pi 4 running Debian-based Linux.

I mapped a local DNS record in my Pi-hole DNS Server:

job.mihlab.me — Demo Site

The domain points to the reverse proxy in my Homelab, which is Nginx Proxy Manager and is also hosted in a Docker container.

In Nginx Proxy Manager, the domain is configured with a wildcard SSL certificate and the stack IP is configured with its port number.

The job.mihlab.me domain is mapped in Cloudflare and points to my Home ISP Dynamic IP for global access.

Note: I forgot the docker command to resolve Service name to docker internal ip so i paused the video exactly on 8:24 just to get my notes and the i typed that command docker exec CONTAINER_NAME getent hosts SERVICENAME

The .env file contains the variables required for the PostgreSQL container:

# PostgreSQL Docker Environment
JOB_POSTGRES_DB=job
JOB_POSTGRES_USER=mih
JOB_POSTGRES_PASSWORD=change-me

The actual .env file does not contains any personal information hence it is uploaded

Given Stacks

  • Web-Page
  • Simple-API
  • Database

As Per Task

I have to create 3 Docker containers using Docker Compose in a single Compose file.

  • Nginx image obtained from Docker Hub.
  • PostgreSQL image obtained from Docker Hub.
  • A mini API created using Flask to return responses for two endpoints:
    • /api/hello
    • /health

Network Architecture

Two Docker networks are used:

  • Web-Net=Frontned html
  • Back-Net=Backend database
  • Nginx is connected only to Web-Net.
  • API is connected to both Web-Net and Back-Net.
  • PostgreSQL is connected only to Back-Net.

This allows the API to communicate with both Nginx and PostgreSQL, while Nginx cannot directly communicate with PostgreSQL.

Accomplished Points

Docker Containers

docker ps is used to show the running Docker containers:

Docker Networks

docker network ls is used to view all the Docker networks:

Database Access

The database is not accessible from the public internet because the PostgreSQL port is not published in the Compose file. Only the API can access the database through the Back-Net network.

To test whether the frontend has access to the database, the following command can be used:

docker exec Nginx-Job getent hosts db

Returning nothing means that the frontend cannot resolve the IP address of the db service because Nginx is not connected to the Back-Net network.

When accessing it through the API, which is connected to both Web-Net and Back-Net, the API can resolve the database because the database is connected through Back-Net:

docker exec Flask-API-Job getent hosts db

This returns the Docker internal IP and its service name, for example:

172.18.0.2    db

This confirms that the API can resolve the PostgreSQL container through Docker's internal DNS.

Database Volume Persistence

The PostgreSQL database uses a Docker volume so that its data persists between:

The volume is not removed when using docker compose down.

External Access

Other than the frontend, the services are not directly accessible from outside the VM.

The API is only accessible through the web container and does not use a published host port.

PostgreSQL also does not use a published host port.

About

Docker Compose contains 3 Stacks

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages