This project uses PostgreSQL with Docker (via Play with Docker / PWD) to ingest CSV data and run analytical queries.
docker-with-Postgres-SQL/
│── docker-compose.yml
│── data/
│ ├── CRMEvents.csv
│ ├── CRMCallCenterLogs.csv
│── queries/
│ ├── avg_agent.sql
│ ├── avg_product.sql
│ ├── avg_res_time.sql
│ ├── top_issue.sql
│── init/
│ └── init.sql
│── README.md
--> Push this folder and all project files (including docker-compose.yml, load_data.sh, and queries) to a GitHub repository.
- Open Play with Docker.\
- Start a new instance.\
- Clone the repository from GitHub:
git clone https://github.com/riansp/docker-with-Postgres-SQL.git
cd docker-with-Postgres-SQLdocker compose up -dCheck running containers:
docker psYou should see the crm_postgres service running with port mapping
5432:5432.
Import CSV files from the data/ folder:
docker exec -i crm_postgres psql -U admin -d crm_db -c "\copy crm_events FROM '/data/CRMEvents.csv' CSV HEADER;"
docker exec -i crm_postgres psql -U admin -d crm_db -c "\copy crm_call_logs FROM '/data/CRMCallCenterLogs.csv' CSV HEADER;"Verify the data:
docker exec -i crm_postgres psql -U admin -d crm_db -c "SELECT * FROM crm_events LIMIT 5;"Several SQL scripts are available in the queries/ folder. Run them as
follows:
docker exec -i crm_postgres psql -U admin -d crm_db -f /queries/avg_agent.sql
docker exec -i crm_postgres psql -U admin -d crm_db -f /queries/avg_product.sql
docker exec -i crm_postgres psql -U admin -d crm_db -f /queries/avg_res_time.sql
docker exec -i crm_postgres psql -U admin -d crm_db -f /queries/top_issue.sql
⚠️ Note: Ensure thequeries/folder is mounted into the container viadocker-compose.yml. Otherwise, move it underdata/queries/so that it is accessible.
To stop the container:
docker compose down- Clone the GitHub repo\
- Run
docker compose up -d\ - Import CSV data using
\copy\ - Execute SQL queries from
.sqlfiles\ - Run
docker compose downwhen finished