<!--
  canonical-url: https://www.avonture.be/blog/docker-python-devcontainer-microsoft
  published:     2024-12-02
  This is a static plain-Markdown mirror generated at build time.
  Visit the canonical URL above for the fully rendered page, with images and interactive components.
-->

# Docker - Even easier setup of Python

> Streamline your Python development. This guide shows you how to use Docker and Microsoft Devcontainers for an incredibly easy and reproducible Python environment setup.

---
![Docker - Even easier setup of Python](/img/v2/devcontainer.webp)

**TL;DR**

This article shows the fastest way yet to get a Python devcontainer: with Docker and the VSCode Docker extension installed, use the Command Palette's built-in "Dev Containers: Add Dev Container Configuration files..." wizard to auto-generate `.devcontainer/devcontainer.json` for Python, then click "Reopen in Container" — no manual file creation needed at all.

Nothing to install, nothing to configure, nothing to create first.

In [a previous article](/blog/docker-python-devcontainer) (and its [Windows-specific follow-up](/blog/docker-python-devcontainer-windows)), I built the `Dockerfile`, `compose.yaml` and `devcontainer.json` files by hand. Turns out VSCode can generate all of that for you.

Here is how to use VSCode and Docker to create a ready-to-use Python environment, whether you're under Windows, Linux, or Mac.

*The wizard is the fastest route, but writing the files yourself is what lets you control exactly what goes into the image — and keep development tooling out of production, as explained in [One Docker Image for Production and Devcontainers - The Clean Way](/blog/docker-prod-devcontainer).*

**The only prerequisites are:**

1. You should have Docker installed on your system

2. You should have Visual Studio Code

3. You've installed the <a href="https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker">Docker for Visual Studio Code</a> addon in VSCode

Here's the payoff. Once the devcontainer is up, create a new file called `main.py` with this line `print("Hello from your Python Devcontainer!")`.

Save the file.

Click in the terminal and type `python main.py` to execute the script and tadaaa:

![Running the script](./images/running_the_script.webp)

A working Python environment, terminal and interpreter ready, and not a single file created by hand. Here's how VSCode builds it for you.

**If you have these three things, just do this:**

1. Start Visual Studio Code

2. Press <kbd>CTRL</kbd>+<kbd>SHIFT</kbd>+<kbd>P</kbd> to open the Command Palette.

3. Select **Dev Containers: Add Dev Container Configuration files...**

4. And follow the wizard:

   * Search for **Python**

   * Select the most recent version of Python, right now it's `3.13-bookworm`

   * No need to install additional features, just press <kbd>Enter</kbd>

   * Same for optional files; not needed, just press <kbd>Enter</kbd>

This done, VSCode will create a file called `.devcontainer/devcontainer.json`.

![VSCode has created the .devcontainer/devcontainer.json file](./images/devcontainer_created.webp)

See bottom right, please click on the `Reopen in Container` button.

Depending on the speed of your computer and if things were already downloaded, you'll get this screen:

![VSCode and its terminal](./images/terminal.webp)

See the bottom part, a terminal window has been displayed and you've a prompt showing `vscode -> /workspaces/python $`.

Click in the terminal and type `python --version`:

![Version](./images/version.webp)
