Contents

Scenario

Advancements in Infrastructure as Code products have driven a lot of automation efficiency on cloud platforms. These IaC products are largely Linux-based and frequently use Python. Python is one of the most popular programming languages and learning (or re-learning) this language will help my cloud journey moving forward.

In order to kill two birds with one stone, I will setup a Linux-based Python environment using containers. I will get an easily created, light-weight Python environment and gain familiarity with Docker containers. I’m an unabashed Microsoft Windows fan, so I looked at using Docker Desktop for Windows to help in creating this Python environment.

Requirements

Before you get started, Docker needs the following requirements in place. These vary depending on whether you have Windows Pro or another version. With Home and Pro can use the Windows Subsytem for Linux (WSL), but With Windows Pro, you can install the Hyper-V feature.

Hardware Requirements

  1. Windows 11 64-bit: Home or Pro version 21H2 or higher, or Enterprise or Education version 21H2 or higher
  2. Windows 10 64-bit: Home or Pro 21H1 (build 19043) or higher, or Enterprise or Education 20H2 (build 19042) or higher.
  3. 64-bit processor with SLAT
  4. 4GB RAM
  5. BIOS-level hardware virtualization support

Enabling the WSL2 feature on Windows

  1. Run PowerShell or Windows Command Prompt as an administrator
  2. Install the wsl feature with the following command: wsl --install
  3. Reboot your system
  4. The default Linux distribution installed is Ubuntu

Enable the Hyper-V feature on windows

  1. Run PowerShell or Windows Command Prompt as an administrator
  2. Install the Hyper-V role with the following command:
    Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
  3. Reboot your system

Software Requirements

Now that the hardware requirements are understood, we can review the software requirements. We only need a few components.

  1. Visual Studio Code
  2. Docker VS Code Extension
  3. Docker Desktop
  4. A Docker Hub account. This is free for Personal use.

Choices

So which way to go? It depends. If you are familiar with Linux or just want a full Linux environment to play and learn with, you should use the Windows Linux Subsystem.

In my case, I will use the Hyper-V feature as I have Windows 10 Pro. I’ve used the WLS2 in the past and since I’m not a full time Linux admin, it was not well maintained. Using Docker allows me to create a standardized Linux-based container and I can easily recreate it if any issue occurs. Recreating the WLS2 is not a trivial procedure.

Creating a Docker Container

I’ll assume you have these components installed. If not, you can follow this guide from Microsoft on installing Visual Studio Code on Windows. You can also read about VS Code Extensions here. Finally, here’s a guide on installing Docker Desktop on Windows.

Start Docker Desktop and sign into your Docker hub account Docker Desktop for Windows

Open Visual Studio Code and click on the Docker VS Code Extension VS Studio Code Under the Help and Feedback section you’ll find additional material to learn more about Docker.

The simplest way to create a Container in Visual Studio Code is to use Dev Containers.

  1. Press F1 or Ctrl+Shift+P to bring up the Command Palette
  2. Start typing Dev Containers and select Dev Containers: Add Dev Container Configuration Files
  3. You will be prompted to select a folder to save the configuration files.
  4. Once VSCode reopens, select Dev Containers: Add Dev Container Configuration Files again and you will get a list of predefined Docker config files that are available.

  1. Search for Python. In this example, I'm choosing *Basic Python*

  1. You can then choose your preferred version of Python.

  1. Finally, you can select any additional features to install.

  1. VSCode will prompt to open the configuration file in a container

  1. Now, VSCode will build the container.

  1. Once the build completes, you will see a container running in Docker Desktop.

Using your new Container

You can access the container in Docker Desktop by clicking on it and going to the Exec tab.

Docker Desktop Exec

You can also write programs and access the container in VSCode.

VSCode Python Container

Conclusion

I hope this post has shown you that you can leverage Docker Desktop and VSCode to create development containers for coding, testing, or whatever need you require. As long as your system meets the requirements covered above, you can run these tools for free.

Learning More

Value for Value

If you received any value from reading this post, please buy me a coffee to show your support.

Thanks for Reading,
Alain Assaf