Skip to content

This guide helps you get started with cloning, running, and deploying this FastAPI + PostgreSQL project using Docker and Kubernetes.

Notifications You must be signed in to change notification settings

Dasmat13/python-docker-dev-example

Β 
Β 

Repository files navigation

Simple python docker dev example for the official docker docs

for link : https://dasmat13.github.io/python-docker-dev-example/#overview https://docs.docker.com/language/python/develop/

<title>Python Docker Dev Example - Setup Guide</title> <style> body { font-family: Arial, sans-serif; max-width: 960px; margin: auto; padding: 2rem; background-color: #f4f4f4; color: #333; } h1, h2, h3 { color: #2c3e50; } pre { background-color: #2d2d2d; color: #f8f8f2; padding: 1em; border-radius: 6px; position: relative; overflow-x: auto; } code { font-family: monospace; } .copy-button { position: absolute; top: 10px; right: 10px; background: #007bff; color: #fff; border: none; padding: 4px 8px; border-radius: 4px; cursor: pointer; } .copy-button:hover { background: #0056b3; } </style>

πŸš€ Python Docker Dev Example - Setup Guide

This guide helps you get started with cloning, running, and deploying this FastAPI + PostgreSQL project using Docker and Kubernetes.

πŸ“¦ Clone the Repository

Copygit clone https://github.com/your-username/python-docker-dev-example.git
cd python-docker-dev-example

βš™οΈ Requirements

  • Python 3.12+
  • Docker & Docker Compose
  • kubectl & Kubernetes cluster (e.g. Minikube)

🐳 Run Locally Using Docker Compose

Copydocker compose up --build

βœ… Verify the App

Copycurl http://localhost:8001/

🧼 Lint and Type Check

Copypip install -r requirements.txt
pip install pre-commit pyright
pre-commit install
pre-commit run --all-files
pyright

☸️ Deploy to Kubernetes

1. Apply Kubernetes Manifest

Copykubectl apply -f docker-postgres-kubernetes.yaml

2. Get Services

Copykubectl get services

3. Get Node Internal IP

Copykubectl get nodes -o wide

4. Access the App (NodePort)

Copycurl http://<INTERNAL-IP>:30001/

πŸ“ Or Use Port Forwarding

Copykubectl port-forward service/service-entrypoint 8001:8001
curl http://localhost:8001/

πŸš‘ Troubleshooting

  • ❌ curl localhost:30001 fails: check pod logs
  • ❌ kubectl apply error: context not set β€” use kubectl config use-context or start cluster

πŸ—‚ Project Structure

.
β”œβ”€β”€ app.py
β”œβ”€β”€ config.py
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ compose.yaml
β”œβ”€β”€ docker-postgres-kubernetes.yaml
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ .pre-commit-config.yaml

πŸ“œ License

MIT

<script> function copyText(button) { const code = button.nextElementSibling.innerText; navigator.clipboard.writeText(code).then(() => { button.innerText = 'Copied!'; setTimeout(() => button.innerText = 'Copy', 2000); }); } </script>

About

This guide helps you get started with cloning, running, and deploying this FastAPI + PostgreSQL project using Docker and Kubernetes.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 56.5%
  • Dockerfile 43.5%