Ditch the ‘Works on My Machine’ Trap: Build Your Own CDE with Coder

DevOps tutorial - IT technology blog
DevOps tutorial - IT technology blog

The High Cost of Local Environment Drift

We’ve all been there. You spend your Monday morning installing specific versions of Node.js, Python, or Docker, only to realize your teammate is running a slightly different patch version. Suddenly, a simple feature branch turns into a four-hour debugging session over environment variables. This is the “it works on my machine” trap, and it costs engineering teams thousands of dollars in lost productivity every sprint.

For a junior developer, setting up a local machine for a complex microservices project can easily swallow three days of work. Modern laptops like the M3 MacBook are incredibly powerful, but they are rarely identical to the Linux environments where your code actually runs.

Cloud Development Environments (CDEs) solve this by moving the workspace from your physical hardware to a standardized container or VM on a central server. This ensures the OS, tools, and configurations are identical for everyone on the team.

I’ve implemented this workflow in production environments, and the reliability is night and day. Onboarding time typically drops from two full days to under fifteen minutes. To achieve this, we’ll use Coder, an open-source platform that transforms any VPS into a centralized hub for dev workspaces.

Why Coder Beats Managed Services

You’ve likely heard of GitHub Codespaces or Gitpod. They are excellent tools, but they often come with a “SaaS tax”—usually around $20 per user, per month, plus compute costs. Coder is different. Because it’s self-hosted and built on Terraform, you keep total control over your data and infrastructure. If you have an idle VPS or an on-premise server, you can host your own platform for the price of the hardware alone.

The Coder Architecture

  • The Coder Server: Your central command center. This dashboard manages users, templates, and active workspaces.
  • Templates: Defined via Terraform. A template acts as a blueprint, specifying that every workspace gets 8GB of RAM, Ubuntu 22.04, and VS Code pre-configured.
  • Workspaces: The actual environments where the coding happens. These usually run as lightweight Docker containers or full Virtual Machines.

By leveraging Terraform, Coder lets you treat your dev environment as code. Need a specialized workspace with an NVIDIA GPU for AI modeling or 32GB of RAM for heavy Java compilation? You just update the template and redeploy.

Let’s Build It: Setting Up Your CDE

To get started, you’ll need a VPS (Ubuntu 22.04 is the sweet spot) with at least 4GB of RAM and Docker installed. You should also have a domain name pointed at your VPS IP to handle secure HTTPS traffic.

Step 1: Deploy Coder with Docker Compose

Docker Compose is the most straightforward path for a self-hosted setup. Start by creating a dedicated directory for your configuration.

mkdir coder && cd coder
nano docker-compose.yaml

The following configuration sets up the Coder server alongside a PostgreSQL database to track your workspace states.

version: "3.9"
services:
  coder:
    image: ghcr.io/coder/coder:latest
    ports:
      - "7080:7080"
    environment:
      CODER_HTTP_ADDRESS: "0.0.0.0:7080"
      CODER_PG_CONNECTION_URL: "postgres://coder:password@database:5432/coder?sslmode=disable"
      # Replace with your actual domain for secure access
      CODER_ACCESS_URL: "https://coder.example.com"
    depends_on:
      database:
        condition: service_healthy
  database:
    image: postgres:14
    environment:
      POSTGRES_USER: coder
      POSTGRES_PASSWORD: password
      POSTGRES_DB: coder
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U coder"]
      interval: 5s
      timeout: 5s
      retries: 5

Fire it up with docker compose up -d. Note that you will need a reverse proxy like Nginx or Caddy to manage SSL certificates. Coder requires HTTPS to handle secure authentication cookies properly.

Step 2: Initialize the CLI

After the server starts, visit your domain in a browser and create your admin account. The dashboard will be empty because we haven’t defined any blueprints yet. Install the Coder CLI on your local machine to push your first template.

curl -L https://coder.com/install.sh | sh
coder login https://coder.example.com

Step 3: Define Your Environment Blueprint

Coder uses starter templates to get you moving quickly. We’ll use a Docker-based template that spins up a container for every new developer workspace.

coder templates init

Choose the “Docker” option. This generates a main.tf file defining the container’s CPU limits, the base image, and persistent volumes. Persistent volumes are crucial; they ensure that when a developer stops their workspace, their work-in-progress code doesn’t vanish into the ether.

Upload your blueprint to the server:

coder templates create standard-dev-env

Step 4: Launching Your Workspace

Head back to the web UI. Under Templates, select your new “standard-dev-env” and click Create Workspace. Name it something like “api-refactor”.

Coder now triggers Terraform to pull the Docker image and initialize the environment. Once the status hits “Running,” you have three ways to work:

  1. Browser Terminal: Perfect for quick hotfixes when you’re away from your main desk.
  2. VS Code Desktop: The gold standard. Use the “Coder” VS Code extension to tunnel into your remote environment via SSH. It feels exactly like local coding.
  3. JetBrains Gateway: Use IntelliJ or PyCharm via the standard SSH connection string provided in the dashboard.

Enforcing Standards via Docker

The real magic happens in the Dockerfile. If your project relies on Go 1.22 and the AWS CLI, you bake them directly into the template. When a new hire joins, they don’t manually install a single binary. They just click a button.

Consider this example for a DevOps-focused workspace:

FROM ubuntu:22.04

RUN apt-get update && apt-get install -y \
    curl git sudo vim wget unzip python3-pip nodejs

# Lock Terraform to a specific version to avoid state file conflicts
RUN wget https://releases.hashicorp.com/terraform/1.7.0/terraform_1.7.0_linux_amd64.zip \
    && unzip terraform_1.7.0_linux_amd64.zip && mv terraform /usr/local/bin/

Smart Resource Management

Running a CDE on a VPS requires a bit of discipline. Coder includes an “Auto-stop” feature that is a lifesaver for your cloud bill. You can set templates to shut down workspaces automatically after 8 hours of inactivity. This prevents forgotten containers from eating up your RAM overnight.

Security is another major win. Since all traffic is encrypted and access is tied to your Coder login (which supports GitHub/GitLab OAuth), your source code stays on your server. It never lives on a developer’s personal laptop, significantly reducing the risk of data leaks from lost or stolen hardware.

The Bottom Line

Moving to a CDE takes the burden of environment management off the developer and puts it where it belongs: in the infrastructure. It eliminates the drift between local and production and makes scaling a team effortless. While setting up Terraform templates requires an initial time investment, the boost in developer happiness and velocity is worth every minute. If you’re tired of debugging “local quirks,” hosting your own CDE is the logical next step for your stack.

Share: