--- title: Setting Up VS Code Server for Remote Development Anywhere description: How to set up and configure VS Code Server for seamless remote development from any device pubDate: 2023-04-18 updatedDate: 2024-04-19 category: Services tags: - vscode - remote-development - self-hosted - coding - homelab heroImage: /blog/images/posts/prometheusk8.png --- If you're like me, you probably find yourself coding on multiple devices - maybe a desktop at home, a laptop when traveling, or even occasionally on a tablet. For years, keeping development environments in sync was a pain point. Enter [VS Code Server](https://code.visualstudio.com/docs/remote/vscode-server), the solution that has completely transformed my development workflow. Today, I want to show you how to set up your own self-hosted VS Code Server that lets you code from literally any device with a web browser, all while using your powerful home server for the heavy lifting. ## Why VS Code Server? Before we dive into the setup, let's talk about why you might want this: - **Consistent environment**: The same development setup, extensions, and configurations regardless of which device you're using. - **Resource optimization**: Run resource-intensive tasks (builds, tests) on your powerful server instead of your laptop. - **Work from anywhere**: Access your development environment from any device with a browser, even an iPad or a borrowed computer. - **Seamless switching**: Start working on one device and continue on another without missing a beat. I've been using this setup for months now, and it's been a game-changer for my productivity. Let's get into the setup! ## Setting Up VS Code Server There are a few ways to run VS Code Server. I'll cover the official method and my preferred Docker approach. ### Option 1: Official CLI Installation The VS Code team provides a CLI for setting up the server: ```bash # Download and install the CLI curl -fsSL https://code.visualstudio.com/sha/download?build=stable&os=cli-alpine-x64 -o vscode_cli.tar.gz tar -xf vscode_cli.tar.gz sudo mv code /usr/local/bin/ # Start the server code serve-web --accept-server-license-terms --host 0.0.0.0 ``` This method is straightforward but requires you to manage the process yourself. ### Option 2: Docker Installation (My Preference) I prefer using Docker for easier updates and management. Here's my `docker-compose.yml`: ```yaml version: '3' services: code-server: image: linuxserver/code-server:latest container_name: code-server environment: - PUID=1000 - PGID=1000 - TZ=America/Los_Angeles - PASSWORD=your_secure_password # Consider using Docker secrets instead - SUDO_PASSWORD=your_sudo_password # Optional - PROXY_DOMAIN=code.yourdomain.com # Optional volumes: - ./config:/config - /path/to/your/projects:/projects - /path/to/your/home:/home/coder ports: - 8443:8443 restart: unless-stopped ``` Run it with: ```bash docker-compose up -d ``` Your VS Code Server will be available at `https://your-server-ip:8443`. ### Option 3: Kubernetes Deployment For those running Kubernetes (like me), here's a YAML manifest: ```yaml apiVersion: apps/v1 kind: Deployment metadata: name: vscode-server namespace: development spec: replicas: 1 selector: matchLabels: app: vscode-server template: metadata: labels: app: vscode-server spec: containers: - name: vscode-server image: linuxserver/code-server:latest env: - name: PUID value: "1000" - name: PGID value: "1000" - name: TZ value: "America/Los_Angeles" - name: PASSWORD valueFrom: secretKeyRef: name: vscode-secrets key: password ports: - containerPort: 8443 volumeMounts: - name: config mountPath: /config - name: projects mountPath: /projects volumes: - name: config persistentVolumeClaim: claimName: vscode-config - name: projects persistentVolumeClaim: claimName: vscode-projects --- apiVersion: v1 kind: Service metadata: name: vscode-server namespace: development spec: selector: app: vscode-server ports: - port: 8443 targetPort: 8443 type: ClusterIP --- apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: vscode-server namespace: development annotations: kubernetes.io/ingress.class: nginx cert-manager.io/cluster-issuer: letsencrypt-prod spec: tls: - hosts: - code.yourdomain.com secretName: vscode-tls rules: - host: code.yourdomain.com http: paths: - path: / pathType: Prefix backend: service: name: vscode-server port: number: 8443 ``` ## Accessing VS Code Server Securely You don't want to expose your development environment directly to the internet without proper security. Here are my recommendations: ### 1. Use a Reverse Proxy with SSL I use Traefik as a reverse proxy with automatic SSL certificate generation: ```yaml # traefik.yml dynamic config http: routers: vscode: rule: "Host(`code.yourdomain.com`)" service: "vscode" entryPoints: - websecure tls: certResolver: letsencrypt services: vscode: loadBalancer: servers: - url: "http://localhost:8443" ``` ### 2. Set Up Authentication The LinuxServer image already includes basic authentication, but you can add another layer with something like Authelia: ```yaml # authelia configuration.yml access_control: default_policy: deny rules: - domain: code.yourdomain.com policy: two_factor subject: "group:developers" ``` ### 3. Use Cloudflare Tunnel For ultimate security, I use a Cloudflare Tunnel to avoid exposing any ports: ```yaml # cloudflared config.yml tunnel: your-tunnel-id credentials-file: /etc/cloudflared/creds.json ingress: - hostname: code.yourdomain.com service: http://localhost:8443 originRequest: noTLSVerify: true - service: http_status:404 ``` ## Configuring Your VS Code Server Environment Once your server is running, it's time to set it up for optimal productivity: ### 1. Install Essential Extensions Here are the must-have extensions I install first: ```bash # From the VS Code terminal code-server --install-extension ms-python.python code-server --install-extension ms-azuretools.vscode-docker code-server --install-extension dbaeumer.vscode-eslint code-server --install-extension esbenp.prettier-vscode code-server --install-extension github.copilot code-server --install-extension golang.go ``` Or you can install them through the Extensions marketplace in the UI. ### 2. Configure Settings Sync To keep your settings in sync between instances: 1. Open the Command Palette (Ctrl+Shift+P) 2. Search for "Settings Sync: Turn On" 3. Sign in with your GitHub or Microsoft account ### 3. Set Up Git Authentication For seamless Git operations: ```bash # Generate a new SSH key if needed ssh-keygen -t ed25519 -C "your_email@example.com" # Add to your GitHub/GitLab account cat ~/.ssh/id_ed25519.pub # Configure Git git config --global user.name "Your Name" git config --global user.email "your_email@example.com" ``` ## Power User Features Now let's look at some advanced configurations that make VS Code Server even more powerful: ### 1. Workspace Launcher I created a simple HTML page that lists all my projects for quick access: ```html