This project demonstrates a simple 2-container Docker setup:
-
UI Container (Flask App)
Receives values from a user and stores them in a database. -
DB Container (Lightweight Alpine)
Holds a persistent SQLite database file using a shared Docker volume.
project/
│
├── ui/
│ ├── app.py # Flask application
│ ├── requirements.txt # Python dependencies
│ ├── Dockerfile # Dockerfile for UI container
│ ├── templates/
│ │ └── index.html # HTML page for the browser UI
│ └── static/
│ └── styles.css # CSS styling for the UI
│
├── db/
│ └── Dockerfile # Minimal Alpine container for database volume
│
└── docker-compose.yml # Docker Compose configuration
The UI is a Python Flask application that:
- Initializes a SQLite database (
database.db) on startup. - Exposes two API routes:
Adds a new value to the DB.
Example request:
curl -X POST http://localhost:5000/add \
-H "Content-Type: application/json" \
-d '{"value": "Hello World"}'Returns all stored values.
Example:
curl http://localhost:5000/listThis container does not run a database engine.
Instead, it:
- Creates a
/datadirectory - Hosts the SQLite database file
- Exposes the folder through a Docker volume, making the data persistent
- Serves as a shared storage backend for the UI container
This architecture keeps the DB separate and easily replaceable.
- A shared volume named
dbdatais created. - The db container exposes
/data. - The ui container mounts the same
/datafolder. - SQLite file
database.dblives inside that shared volume.
git clone <your-repository-url>
cd projectdocker compose up --buildYou will see:
db_service→ starts and waitsui_service→ starts Flask on port 5000
http://localhost:5000- Enter a value in the input field and press "Add" button or press the Enter key.
- Values are displayed in a table below.
- The table automatically refreshes every 2 seconds to show all stored values.
git clone <your-repository-url>
cd projectdocker compose up --buildYou will see:
db_service→ starts and waitsui_service→ starts Flask on port 5000
curl -X POST http://localhost:5000/add \
-H "Content-Type: application/json" \
-d '{"value": "Test"}'curl http://localhost:5000/listcurl -X POST http://localhost:5000/add -H "Content-Type: application/json" -d '{"value": "This is only a test"}'{"message":"Value inserted successfully"}curl http://localhost:5000/list[{"id":1,"value":"This is only a test"}]docker compose downTo delete the persistent DB:
docker volume rm project_dbdata- Database persists even after containers stop.
- You can swap SQLite for PostgreSQL easily later.
- Very useful structure for learning multi-container apps.