As a coder, setting up a development environment can be challenging. In this article, we’ll show you how to create a perfect Linux programming platform using VSCode and containers.
To start, install Docker or Podman on your system. Both applications allow you to create and manage containers. For simplicity, use Podman if your Linux distro is a derivative of Red Hat, such as Fedora Workstation or CentOS. If neither is installed, choose the one that best suits your needs.
Create a subdirectory called `.devcontainer` in your project folder with a `devcontainer.json` file inside. This file contains information for setting up the development container you want to use for this project. An example `devcontainer.json` file might look like this:
“`json
{
“name”: “Fedora Node.js Container”,
// Pull latest available Fedora docker image
“image”: “fedora:latest”,
// Set container workspace directory
“workspaceFolder”: “/workspace”,
// Bind local workspace to container workspace
“workspaceMount”: “source=${localWorkspaceFolder},target=/workspace,type=bind,Z”,
// Install git, github cli, nodejs
“postCreateCommand”: “dnf install -y git gh nodejs”
}
“`
The first line gives the container a name, the second line tells the extension what image to pull to create the operating system for the container. The third line sets the container workspace directory and binds your actual working folder with the virtual `workspace` folder within the container.
Once you’ve created the `devcontainer.json` file, VSCode should recognize it and prompt you to re-open your workspace inside the container. You can force the container to build or rebuild by pressing `Ctrl+Shift+P` and entering “build” in the search box.
You’ll be working within the container, which is now complete! Your development tools will stay in the container, and your code will stay on your local drive. The key benefit of this setup is that you can adjust your operating system without breaking your development environment and vice versa.
With this setup, you can rebuild your container with new tools or change the operating system without worrying about creating conflicts or damaging your own operating system. If something goes wrong, you can easily rebuild and get your perfect development platform back up and running in minutes.
Source: https://www.howtogeek.com/how-i-built-the-perfect-programming-platform-in-minutes