(01)Install
1sudo apt-get install -y postgresql postgresql-contrib2sudo systemctl enable postgresqlAdvanced open-source relational database
What is this?
PostgreSQL is a powerful open-source database used by apps that need reliable, complex data storage.
Where to create or edit the main configuration — paths below match the setup steps.
/etc/postgresql/*/main/postgresql.confLocation: PostgreSQL server
Memory, connections, logging
/etc/postgresql/*/main/pg_hba.confLocation: PostgreSQL server
Client authentication rules
Step 01
1sudo apt-get install -y postgresql postgresql-contrib2sudo systemctl enable postgresqlStep 02
1sudo -u postgres psql2CREATE USER myuser WITH PASSWORD 'mypass';3CREATE DATABASE mydb OWNER myuser;4\qStep 03
1psql -U myuser -d mydb -c 'SELECT version();'Step 04
1pg_dump mydb > backup.sql2psql mydb < backup.sql4 YAML templates for PostgreSQL. Copy and deploy after setup.
4 ready-to-copy templates. Expand one, copy the YAML, then run the deploy commands.
docker-compose.yaml
PostgreSQL database + Flask app with env file and volume persistence
1version: "3.9"2 3services:4 db:5 image: postgres:15-alpine6 environment:7 POSTGRES_DB: dukaan_db8 POSTGRES_USER: dukaan9 POSTGRES_PASSWORD: dukaan12310 ports:11 - "5432:5432"12 volumes:13 - pgdata:/var/lib/postgresql/data14 15 app:16 build: .17 ports:18 - "5000:5000"19 env_file:20 - .env21 depends_on:22 - db23 24volumes:25 pgdata:Dockerfile
Flask application container image
1FROM python:3.12-slim2WORKDIR /app3COPY requirements.txt .4RUN pip install --no-cache-dir -r requirements.txt5COPY . .6EXPOSE 50007CMD ["python", "app.py"]Step 01
1cd your-project/2docker compose up -d --build3docker compose ps4docker compose logs -f app1docker compose down2docker compose down -v # remove volumes