Docker Integration in VSCode
Welcome to another episode of Bite-Sized. In this video, we'll connect Docker with VSCode and show you how to actually work inside a Docker container.
Instead of just running containers in the terminal, you can use VSCode to work directly inside them as if they were your local machine. Your code editor, terminal, and extensions all run inside the exact research environment you defined.
Installing the Dev Containers Extension
To use Docker inside VSCode, you need one specific extension:
- Open the Extensions tab on the left.
- Search for "Dev Containers" by Microsoft.
- Click Install.
Reopening a Folder in a Container
Before starting, make sure your project has a Dockerfile to define your environment, such as the Python version and required packages.
- Open your project folder in VSCode normally.
- Press Ctrl + Shift + P (or Cmd + Shift + P on Mac) to open the Command Palette.
- Type "Dev Containers: Reopen in Container" and select it.
VSCode will build the Docker image, start the container, and reopen your folder inside it. You will know you are successful when you see a green indicator in the bottom-left corner showing you are connected to a Dev Container.
Opening a GitHub Repository
You can go a step further and clone a GitHub repository directly into a container:
- Copy the repository URL from GitHub.
- In VSCode, open the Command Palette and select "Git: Clone".
- Paste the URL and choose a folder.
Note: For VSCode to automatically detect and open the project in a container, the repository needs both a
Dockerfileand adevcontainerconfiguration.
A script might run fine on your machine but throw errors on someone else's due to a wrong Python version, missing packages, or a different system setup. Cloning and opening a repository inside a predefined container ensures everyone uses the exact same environment, drastically reducing reproducibility problems.