Add file.sh for docker

This commit is contained in:
Charlyne Wargnier-Potier 2025-03-19 06:32:59 +00:00
commit 74fafa1960
4 changed files with 60 additions and 0 deletions

13
z1/prepare-app.sh Normal file
View File

@ -0,0 +1,13 @@
#!/bin/bash
echo "Preparing app"
# Create the Docker volume if it doesn't exist
docker volume create pgdata
# Create the custom Docker network
docker network create app_net 2>/dev/null || echo "Network app_net already exists."
# Build the Flask application image from the Dockerfile in the ./app folder.
docker build -t flask_app_image ./app
echo "Prepa completed."

12
z1/remove-app.sh Normal file
View File

@ -0,0 +1,12 @@
#!/bin/bash
echo "Removing app"
# Remove the containers forcefully.
docker rm -f flask_app postgres_db
# Remove the custom network and volume if they exist.
docker network rm app_net 2>/dev/null || echo "Network app_net already removed."
docker volume rm pgdata 2>/dev/null || echo "Volume pgdata already removed."
echo "Application removed."

28
z1/start-app.sh Normal file
View File

@ -0,0 +1,28 @@
#!/bin/bash
echo "Starting app"
# Run PostgreSQL container
docker run -d --name postgres_db \
--network app_net \
-e POSTGRES_USER=user \
-e POSTGRES_PASSWORD=password \
-e POSTGRES_DB=sampledb \
-v pgdata:/var/lib/postgresql/data \
--restart always \
postgres:13
# Wait a few seconds to ensure PostgreSQL starts before the Flask app connects.
sleep 10
# Run Flask application container
docker run -d --name flask_app \
--network app_net \
-p 5000:5000 \
--restart always \
-e DB_HOST=postgres_db \
-e POSTGRES_USER=user \
-e POSTGRES_PASSWORD=password \
-e POSTGRES_DB=sampledb \
flask_app_image
echo "The application is available at http://localhost:5000"

7
z1/stop-app.sh Normal file
View File

@ -0,0 +1,7 @@
#!/bin/bash
echo "Stopping app"
docker stop flask_app postgres_db
echo "Application stopped."
~