Run PySpark and Delta Lake in VS Code With a Docker Dev Container

If you prefer VS Code to a browser editor, the Spark Lab gives you a ready workspace: a Dev Container that runs the same lab image, a notebook with every lesson, and your own files. Open the folder, click Reopen in Container, and run.

Open the Spark Lab

Steps

1. Install Docker Desktop and VS Code.

2. Run the Set up command from the Spark Lab page once. It builds the lab image.

3. On the Spark Lab page click **VS Code workspace** and unzip the download.

4. Open the folder in VS Code. Accept the Dev Containers extension, then click **Reopen in Container**.

5. Open `spark_lab.ipynb`, pick the Python kernel and run the cells. The Spark UI is at http://localhost:4040 while the notebook runs.

What is in the workspace

  • `.devcontainer/devcontainer.json`: the lab image, the shared data volume, port 4040 and the Python and Jupyter extensions.
  • `spark_lab.ipynb`: every lesson, Spark basics and Delta Lake, as cells.
  • `lessons/*.py` and `my_files/*.py`: the lessons and the files you made in the browser editor.

Good to know

  • Delta Lake is on for every Spark session in the image, so plain scripts can write Delta tables.
  • The data volume is the same one the browser lab uses, so tables you write in VS Code show up there too.
  • Stop the browser lab first if it runs: both use port 4040.

Open the Spark Lab

Also try

How to use the Spark Lab: step by step

  1. Run the Set up command once
  2. Download the VS Code workspace
  3. Reopen in Container
  4. Run the notebook

When to use the Spark Lab

  • Working in your own editor with Git
  • Running notebooks with Spark locally
  • Using Copilot or other VS Code extensions on Spark code