Zero Set-up Development Environment with Dev Containers

June 24, 2024 | 4 min Read

In the ever-evolving landscape of software development, achieving a consistent development environment across different machines has always been a challenging task. The age-old adage “It works on my machine” has frustrated developers for decades, leading to inefficiencies and delays in project timelines. Cloud-based IDEs promise to solve this issue. They are on a rise, but are not yet ubiquitously deployed. However, a lesser-known but powerful feature, dev containers, offers a pretty pragmatic and robust solution to the developer environment set-up issue.

What Are Dev Containers?

Dev containers enable software projects to specify a Docker container as a development environment, ensuring consistency and reliability across different setups. By defining a devcontainer.json file, you can provide all developers on a specific project with a predefined, fully functional development environment. This eliminates the need for complex local setups and ensures that every team member is working in the same environment.

The Power of Dev Containers

The true power of dev containers lies in their ability to standardize the development environment. This approach has several significant advantages:

  1. Consistency Across Development Environments: By using a dev container, you can ensure that every developer is working with the same environment with the same versions of tools, libraries, and configurations. This uniformity prevents the common “it works on my machine” issues.

  2. Simplified Onboarding: New team members can get started quickly without spending hours setting up their environment. By simply launching the workspace within a started Docker container, they have everything they need preinstalled and are ready to go.

  3. Time Savings: Dev containers save valuable time that would otherwise be spent troubleshooting environment-specific issues. Developers can focus on writing code instead of dealing with setup problems.

  4. Portability and Flexibility: Dev containers offer a lightweight and pragmatic solution for development. Unlike moving the entire development environment to the cloud, dev containers allow you to maintain control over your local environment while benefiting from the containerized setup. Also deployment can be significantly simplified, as the same container can be used in production bringing the development and production environments closer together.

  5. Enhanced Security: Since the development environment is containerized, processes cannot execute directly on the developer’s machine. This isolation helps mitigate the risk of supply chain attacks, as any potentially malicious code is confined within the container and cannot affect the host system.

How to Use Dev Containers

Using dev containers is straightforward. Here’s how you can set it up:

  1. Define the Dev Container: Create a devcontainer.json file in your project. This file specifies the Docker image and any necessary configurations. Here is an easy example:

    {
      "name": "Go Development",
      "image": "golang:latest",
      "features": {
        "dev": true
      },
      "extensions": [
        "ms-vscode.go"
      ]
    }
    
  2. Launch the Dev Container: Using an IDE that supports dev containers, such as Theia IDE or VS Code, you can spin up the defined Docker container and launch your workspace within the container. The IDE mounts your workspace directory from your local OS and moves all processes, except for the user interface of the IDE, into the container, including compilers, language services, terminals, and debug sessions, without impacting the developer experience in using a local IDE.

  3. Start Coding: Once inside the container, you have access to all the tools and libraries specified in the devcontainer.json. For instance, even if Go is not installed on your host machine, it will be available within the dev container.

Real-World Example

Consider a website project using Hugo that also requires Go for development. On your local machine, Go might not be installed. However, with a dev container, you can specify a Docker image that includes Go. As shown in the screenshot below, the host machine lacks Go, but the dev container has it preinstalled, ensuring a seamless development experience. The prerequisites are not only installed, everybody is also using the exact same versions, which avoids a lot of trouble in practice.

Encouraging the Use of Dev Containers

We strongly encourage projects to adopt dev containers as a default practice. The benefits in terms of simplified onboarding, consistent environments, time savings, and enhanced security are substantial. By reducing the overhead associated with environment setup, teams can focus on what truly matters: developing great software. Modern IDEs such as the Eclipse Theia IDE or VS Code support the feature out of the box! Give dev containers a try in your next project and experience the difference they make in your development workflow.

Jonas, Maximilian & Philip

Jonas Helming, Maximilian Koegel and Philip Langer co-lead EclipseSource. They work as consultants and software engineers for building web-based and desktop-based tools. …