Databricks
This guide shows you how to simulate a Databricks environment locally using Docker, MinIO as S3-compatible storage, and PostgreSQL as a persistent Hive Metastore. This lab demonstrates how to develop and test Spark and Delta Lake ETLs locally using Databricks Runtime 15.4 LTS (Spark 3.5.0).
Prerequisites
Section titled “Prerequisites”- Docker installed and running.
- Dev Containers extension installed (optional).
How to execute
Section titled “How to execute”-
Setup Environment:
Open VS Code in the project folder and execute this command in the Command Palette:
Terminal window > Dev Containers: Reopen in Container- Start Infrastructure: Launch all required services (Spark, MinIO, PostgreSQL).
Terminal window docker compose up -d - Run the setup script inside the Spark container to install tools and dependencies.
Terminal window docker compose exec spark bash scripts/setup.sh
- Start Infrastructure: Launch all required services (Spark, MinIO, PostgreSQL).
-
Run the Example:
Terminal window python main.pyExecute the script inside the Spark container:
Terminal window docker compose exec spark .venv/bin/python main.py
How to debug
Section titled “How to debug”- Python Script (main.py):
- Open
main.pyand set breakpoints. - Run the Python: Main configuration from the Run and Debug tab.
- Open
- Interactive Notebook:
- Open
src/notebooks/analysis.ipynband debug cells with the Jupyter debugger.
- Open
How to test
Section titled “How to test”- All tests: Run the automated script:
scripts/run_tests.sh - Individually: Use the VS Code Testing tab to run or debug specific test cases.
Validate results
Section titled “Validate results”While a job is running, Open the Spark UI:
http://localhost:4040Browse the Delta files written to the bucket. Log in with MINIO_ROOT_USER / MINIO_ROOT_PASSWORD:
http://localhost:9001Clean Up
Section titled “Clean Up”docker compose down -vTroubleshooting
Section titled “Troubleshooting”| Issue | Solution |
|---|---|
| Connection Refused | Ensure all services are running: docker compose ps |
| Table already exists | Drop the conflicting table with spark.sql("DROP TABLE IF EXISTS sales.products_silver") or run Clean Up to reset the volumes. |