How to Run AI For Beginners Lessons in VS Code Using Dev Containers

The AI For Beginners repository includes a ready-made VS Code dev container configuration that automatically provisions a complete Python 3 environment with TensorFlow, PyTorch, and all required packages inside an isolated Docker container.

The Microsoft AI For Beginners curriculum provides hands-on Jupyter notebook lessons covering fundamental AI concepts. Configuring the correct Python runtime with compatible library versions can be challenging across different operating systems. By using the Dev Containers feature in VS Code, you can run AI For Beginners lessons in VS Code using dev containers to ensure a consistent, reproducible environment that matches the course authors' exact specifications.

Opening the Repository

Begin by cloning the repository to your local machine or opening it directly from GitHub. You can use the "Clone Repository in VS Code" option from the GitHub interface or run:

git clone https://github.com/microsoft/AI-For-Beginners.git

Once opened, VS Code automatically detects the .devcontainer directory containing the development environment definition.

Launching the Development Container

When VS Code identifies the .devcontainer/devcontainer.json file, a notification banner appears prompting you to "Reopen in Container". Click this banner, or manually trigger the command by pressing F1 and selecting:

Dev Containers: Reopen in Container

VS Code initiates the container build process by reading .devcontainer/devcontainer.json. The configuration uses .devcontainer/Dockerfile to construct an image based on mcr.microsoft.com/vscode/devcontainers/python:3.11, installing system-level dependencies and preparing the Python runtime.

Environment Initialization and Setup

Upon container creation, the postCreateCommand defined in .devcontainer/devcontainer.json executes automatically. This script creates and activates the Conda environment using the repository's environment.yml file:

conda env create -f environment.yml
conda activate ai4beg

The environment installation process includes:

  • Core ML libraries: TensorFlow, PyTorch, Keras, and scikit-learn as specified in environment.yml
  • Computer vision packages: OpenCV and related dependencies
  • Additional utilities: Packages listed in .devcontainer/requirements.txt installed via pip

This automated setup ensures all lesson dependencies are available without manual configuration.

Running Lessons and Jupyter Notebooks

With the container running and environment activated, navigate to any lesson file located at lessons/<topic>/<lesson>.ipynb. You have two options for execution:

Option 1: Launch Jupyter Lab

jupyter lab

Option 2: Use VS Code's Native Notebook Support

Open .ipynb files directly in VS Code. The notebook kernel automatically points to the ai4beg Conda environment created during container initialization, allowing you to execute cells interactively.

All required libraries—including TensorFlow, PyTorch, and OpenCV—are pre-installed and configured within the container's isolated filesystem.

Configuring GPU Support (Optional)

If your host machine has a GPU-enabled Docker runtime, you can modify .devcontainer/Dockerfile to include CUDA libraries and GPU drivers. The dev container configuration is compatible with VS Code's Remote-Containers GPU extensions, allowing you to leverage hardware acceleration for deep learning lessons without modifying your local system.

Understanding the Dev Container Configuration

The repository's containerized environment is defined by four key files:

  • .devcontainer/devcontainer.json: Defines the VS Code development container settings, including the Docker image reference, recommended extensions, port forwarding, and lifecycle commands like postCreateCommand
  • .devcontainer/Dockerfile: Contains instructions for building the custom image, specifying the base Python image, and installing system dependencies
  • .devcontainer/requirements.txt: Lists additional Python packages installed via pip during the container build
  • environment.yml: Conda environment file that pins exact versions of TensorFlow, PyTorch, Keras, OpenCV, and other machine learning libraries to ensure reproducibility

Summary

  • The AI For Beginners repository provides a complete dev container configuration in the .devcontainer/ directory
  • Opening the repository in VS Code triggers the "Reopen in Container" prompt, which builds an isolated Python 3.11 environment
  • The postCreateCommand automatically executes conda env create -f environment.yml to install all required ML libraries
  • Lessons located in lessons/<topic>/<lesson>.ipynb run immediately without local Python installation
  • GPU support is available by modifying .devcontainer/Dockerfile to include CUDA libraries

Frequently Asked Questions

Do I need to install Python or Conda on my local machine?

No. The dev container encapsulates the entire Python runtime and Conda environment inside Docker. Your local machine only requires VS Code, the Dev Containers extension, and Docker Desktop. All Python dependencies are installed within the container's filesystem.

Can I use GitHub Codespaces instead of local Docker?

Yes. The repository supports opening directly in GitHub Codespaces, which utilizes the same .devcontainer/devcontainer.json configuration. Select "Open in Codespaces" from the GitHub repository page to launch a cloud-hosted development environment with identical configuration to the local dev container.

How do I install additional packages in the dev container?

You can install temporary packages using pip install or conda install inside the running container's terminal. For permanent additions, modify .devcontainer/requirements.txt (for pip packages) or environment.yml (for Conda packages), then rebuild the container using the VS Code command "Dev Containers: Rebuild Container".

What should I do if the container build fails?

Check the VS Code Dev Containers output log for specific errors. Common issues include Docker daemon not running, insufficient disk space, or network restrictions blocking package downloads. Ensure Docker Desktop has adequate resources allocated (minimum 4GB RAM recommended for machine learning workloads) and that the environment.yml file is not corrupted.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →