# Coder + PostgreSQL

> Self-hosted remote development environments.

- Category: Development Tools
- Difficulty: intermediate
- Components: coder, postgresql
- Tags: coder, remote-development, ide, workspace, cloud-dev
- Source: https://docker.recipes/development/coder-workspace

## Overview

Coder is an open-source platform that provisions secure, standardized development environments in your cloud or datacenter. Originally developed to solve the challenges of remote development and developer onboarding, Coder creates consistent, reproducible workspaces that developers can access from anywhere using their favorite IDEs like VS Code, JetBrains, or vim. Unlike traditional local development setups, Coder workspaces run on powerful cloud infrastructure while maintaining the familiar development experience.

This stack combines Coder's workspace orchestration with PostgreSQL as the backend database, creating a production-ready remote development platform. PostgreSQL stores all workspace metadata, user sessions, audit logs, and template configurations with the reliability and ACID compliance that enterprise development teams require. The database handles complex queries for workspace analytics, user permissions, and resource tracking across potentially hundreds of concurrent development environments.

Development teams transitioning to remote work, organizations with complex onboarding processes, and companies managing developers across multiple projects will find this combination invaluable. Coder eliminates 'works on my machine' problems by standardizing development environments, while PostgreSQL ensures that workspace state, user data, and audit trails are preserved with enterprise-grade reliability. This is particularly powerful for teams working with resource-intensive applications, legacy codebases, or strict security requirements where local development isn't feasible.

## Features

- Template-based workspace provisioning with Terraform for consistent development environments across teams
- IDE-agnostic development supporting VS Code, JetBrains IDEs, vim, and web-based terminals
- Resource quotas and automatic workspace shutdown to control cloud infrastructure costs
- Built-in SSH and port forwarding for secure access to development services and databases
- Workspace sharing and collaboration features for pair programming and code reviews
- PostgreSQL-backed audit logging with full ACID compliance for enterprise compliance requirements
- Git integration with automatic repository cloning and credential management
- Container and VM workspace support through Docker and Kubernetes providers

## Use cases

- Remote development teams needing consistent environments across macOS, Windows, and Linux developers
- Onboarding new developers with pre-configured workspaces containing all necessary tools and dependencies
- Companies with complex development stacks requiring GPU access, large datasets, or specialized hardware
- Organizations with strict security policies requiring air-gapped or controlled development environments
- Consulting firms managing multiple client projects with different technology stacks and access requirements
- Educational institutions providing standardized programming environments for computer science courses
- Open source projects enabling contributors to start coding immediately without complex local setup

## Prerequisites

- Docker Engine with access to Docker socket for workspace container management
- Minimum 4GB RAM available (2GB for Coder, 1GB for PostgreSQL, 1GB for workspace overhead)
- Port 7080 available for Coder web interface access
- Basic understanding of Terraform for creating custom workspace templates
- PostgreSQL knowledge for database maintenance and backup procedures
- Network access to container registries for pulling workspace images

## docker-compose.yml

```yaml
services:
  coder:
    image: ghcr.io/coder/coder:latest
    environment:
      - CODER_PG_CONNECTION_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/coder?sslmode=disable
      - CODER_HTTP_ADDRESS=0.0.0.0:7080
      - CODER_ACCESS_URL=http://localhost:7080
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - coder-data:/home/coder/.config
    ports:
      - "7080:7080"
    depends_on:
      - postgres
    networks:
      - coder-network
    restart: unless-stopped

  postgres:
    image: postgres:15
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=coder
    volumes:
      - postgres-data:/var/lib/postgresql/data
    networks:
      - coder-network
    restart: unless-stopped

volumes:
  coder-data:
  postgres-data:

networks:
  coder-network:
    driver: bridge
```

## .env

```bash
# Coder
POSTGRES_USER=coder
POSTGRES_PASSWORD=secure_postgres_password

# Create first user: coder server create-admin-user
```

## Usage notes

- Web UI at http://localhost:7080
- Create admin on first run
- Templates for workspaces
- Docker, Kubernetes providers
- VS Code integration

## Troubleshooting

- Coder fails to connect to PostgreSQL: Verify POSTGRES_USER and POSTGRES_PASSWORD environment variables match between services
- Workspaces fail to start with 'docker socket permission denied': Ensure Docker socket has proper permissions or add coder user to docker group
- Template builds timeout or fail: Check Docker daemon resources and increase build timeout in Coder admin settings
- Users can't access workspace ports: Configure CODER_ACCESS_URL to match your actual domain/IP instead of localhost
- PostgreSQL connection pool exhausted: Increase max_connections in PostgreSQL config or reduce concurrent workspace limits
- Workspace data lost after container restart: Verify coder-data volume is properly mounted and persistent

