This is my practice project for learning Docker and Kubernetes from scratch. The idea is simple: take a static website template (HTML/CSS), package it into a Docker image running Apache (httpd), then deploy that image to a Kubernetes cluster using a Deployment and a Service.
I've been learning the basics of containers and orchestration. Instead of just reading theory, I wanted to get hands-on: build my own image, run it in Docker, then go all the way through deploying it to Kubernetes so I could actually see the flow from building an image to it running in a cluster.
.
├── Dockerfile # image definition: web server + template
├── .dockerignore
├── k8s/
│ ├── deployment.yaml # Deployment for running the web pods
│ └── service.yaml # Service to expose the pods
└── README.md
The base image is Rocky Linux 9. I originally used centos:latest, but I later found out the official CentOS image on Docker Hub is deprecated and all its tags are EOL, so yum install would fail since the mirrors are no longer active. I switched to Rocky Linux because it's a drop-in replacement for CentOS, so none of my yum commands needed to change.
What the Dockerfile does:
- Installs
httpd,zip,unzip. - Downloads the Loxury static template from free-css.com directly at build time (
ADDfrom a URL). - Extracts the zip, moves the contents into
/var/www/html, then removes the leftover zip/folder that's no longer needed. - Runs
httpdin the foreground so the container doesn't exit immediately.
Template credit: Loxury from free-css.com.
Build the image:
docker build -t loxury-web:latest .Run the container:
docker run -d -p 8080:80 --name loxury-web loxury-web:latestOpen http://localhost:8080 in your browser.
First, push the image to a registry (Docker Hub or any other registry you use), and update the image name in k8s/deployment.yaml (image: toriqnain/loxury-web:latest) to match your own image if it's different.
docker tag loxury-web:latest toriqnain/loxury-web:latest
docker push toriqnain/loxury-web:latestApply the manifests to your cluster (I tested this on Minikube):
kubectl apply -f k8s/deployment.yaml
kubectl apply -f k8s/service.yamlCheck pod and service status:
kubectl get pods
kubectl get svc loxury-web-serviceIf you're on Minikube, open the service with:
minikube service loxury-web-service- Add
livenessProbeandreadinessProbeto the Deployment to make it more production-ready. - Try switching from
NodePorttoIngressonce I learn more about Ingress Controllers. - Multi-stage build to make the image smaller (it's still single-stage for now).
- Add a simple CI pipeline (GitHub Actions) to auto build & push the image.
The code in this repo is free to use for learning purposes. The Loxury template itself follows the license from free-css.com.