Job-ch/
├── api/
│ ├── Dockerfile
│ └── app.py
├── nginx/
│ └── default.conf
├── compose.yml
├── index.html
├── .env
├── .gitignore
└── README.md
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:
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-meThe actual
.envfile does not contains any personal information hence it is uploaded
- Web-Page
- Simple-API
- Database
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
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-NetandBack-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.
docker ps is used to show the running Docker containers:
docker network ls is used to view all the Docker networks:
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 dbReturning 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 dbThis 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.
The PostgreSQL database uses a Docker volume so that its data persists between:
The volume is not removed when using docker compose down.
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.