Download and install Visual Studio Code from the official website.
Ensure Docker is installed on your machine. You can download it from the official Docker website.
Open the project you want to work on in Visual Studio Code.
Install the Remote Development extension pack in Visual Studio Code. This pack includes extensions that enable you to work with development environments in containers, WSL, or SSH. You can find the extension pack here.
Press Ctrl+Shift+P
(Windows/Linux) or Cmd+Shift+P
(macOS) to open the Command Palette.
Type and select "Remote-Containers: Add Development Container Configuration Files" from the Command Palette. Choose a predefined configuration (e.g., Node.js, Python, etc.) or select "Other" to create a custom configuration.
If you selected "Other," customize the devcontainer.json
file according to your project's needs, specifying the required tools, extensions, and settings for the DevContainer.
Open the Command Palette again and select "Remote-Containers: Reopen in Container." Visual Studio Code will build the Docker image, set up the DevContainer, and reopen your project within the container.
You are now working within the DevContainer. Make your changes, write code, and use the integrated tools and extensions.
Save your changes within the DevContainer. All changes are saved to your local workspace and are persistent across container restarts.
To stop the DevContainer, click on the bottom-left corner where it says "DevContainer" and choose "Stop Container." To restart, use "Reopen in Container" again.