.. | ||
app | ||
prepare-app.sh | ||
README.md | ||
remove-app.sh | ||
start-app.sh | ||
stop-app.sh |
Docker Web Application Deployment (Without Docker Compose)
Overview
This project deploys a multi-container Docker application consisting of:
- Flask Web App: A Python Flask application that connects to a PostgreSQL database.
- PostgreSQL Database: Uses the official PostgreSQL image with persistent storage via a named volume.
Both containers communicate over a custom Docker network (app_network
).
Required Software
- Operating System: Linux (with Docker support)
- Docker: Installed and configured
- Bash: For running the provided scripts
Components
Flask Web Application
- Image: Built locally from the Dockerfile in the
app/
folder. - Container Name:
flask_app
- Port Mapping: Host port
5000
mapped to container port5000
. - Environment Variables: Set via the
docker run
command to point to the database.
PostgreSQL Database
- Image:
postgres:13
- Container Name:
postgres_db
- Environment Variables:
POSTGRES_USER=user
POSTGRES_PASSWORD=password
POSTGRES_DB=sampledb
- Volume: Named volume
pgdata
is mounted at/var/lib/postgresql/data
for persistent storage.
Virtual Network and Volume
- Network:
app_network
– A custom Docker bridge network for inter-container communication. - Volume:
pgdata
– Persists PostgreSQL data between container restarts.
How to prepare, run, pause and delete the application
Step 1: Prepare the application
This will create the necessary volume, network, and build the Flask image.
./prepare-app.sh
Step 2: Run the application
This will start the PostgreSQL database and Flask web application containers.
./start-app.sh
Step 3: Stop the application
It will stop the containers
./stop-app.sh
Step 5: Remove the application
This will stop and remove the containers, network, and volume.
./remove-app.sh