Remote & Dev Containers
VS Code Remote Development lets you edit code that lives elsewhere — SSH host, dev container, WSL, GitHub Codespaces — while the UI runs locally. The extension marketplace, debugger, terminal all act as if the code were native; behind the scenes a server runs on the remote.
SSH, containers, WSL, Codespaces
EXAMPLE
# 1) The Remote Development extension pack
# Install from the marketplace: 'Remote Development' (Microsoft)
# Bundle includes:
# • Remote - SSH
# • Remote - Tunnels
# • Dev Containers
# • WSL (Windows only)
# For Codespaces: 'GitHub Codespaces' extension (auto-installed by GitHub)
# Architecture:
# Local VS Code (UI, settings, extensions)
# ⇅ VS Code Server (runs on remote)
# ⇅ Remote filesystem + tools
# 2) Remote - SSH (most common)
# Prerequisites:
# • SSH client on local machine
# • SSH access to a Linux/macOS host (Linux preferred)
# • Tool path on remote: bash, curl, tar
# Connect:
# 1) Cmd/Ctrl+Shift+P → 'Remote-SSH: Connect to Host'
# 2) Pick host from ~/.ssh/config or 'Add New SSH Host'
# 3) VS Code installs vscode-server on remote (~ 200 MB cached)
# 4) Open folder on remote
# ~/.ssh/config example
Host dev-box
HostName dev.example.internal
User mara
IdentityFile ~/.ssh/dev_ed25519
ForwardAgent yes
Host jump-prod
HostName bastion.example.com
User mara
IdentityFile ~/.ssh/jump_ed25519
Host prod-app
HostName 10.0.0.42
User mara
ProxyJump jump-prod
# Now: 'Connect to Host' → dev-box → workspace files load.
# 3) Settings — local vs remote
# • Local settings.json: editor UI, themes
# • Remote settings.json: workspace-specific, language tooling, formatters
# • Workspace settings: committed to repo (.vscode/settings.json)
# Extensions are split:
# • UI extensions stay LOCAL (themes, keymap)
# • Workspace extensions install on REMOTE (language servers, debuggers)
# Settings sync still works across local sessions.
# 4) Dev Containers
# Code lives in a Docker container. Reproducible env per project.
# .devcontainer/devcontainer.json
{
"name": "My Project",
"image": "mcr.microsoft.com/devcontainers/typescript-node:20",
"customizations": {
"vscode": {
"extensions": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
],
"settings": {
"editor.formatOnSave": true
}
}
},
"forwardPorts": [3000, 5432],
"postCreateCommand": "npm install",
"remoteUser": "node"
}
# Use: Cmd/Ctrl+Shift+P → 'Dev Containers: Reopen in Container'
# VS Code builds the container + connects to it.
# Features for Postgres, Redis, etc:
{
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/github-cli:1": {}
}
}
# Docker Compose-backed dev containers
{
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspaces/myapp"
}
# 5) WSL (Windows Subsystem for Linux)
# • Install Ubuntu via 'wsl --install -d Ubuntu-22.04'
# • Cmd/Ctrl+Shift+P → 'WSL: Connect to WSL' or 'WSL: New WSL Window'
# • Code on Linux filesystem, edit from Windows UI
# • Performance: keep code in WSL filesystem (/home/user) NOT /mnt/c (mount slowdown)
# 6) GitHub Codespaces — cloud-hosted dev containers
# • github.com/<repo> → green Code button → Codespaces tab
# • Or VS Code Command Palette: 'Codespaces: Create New Codespace'
# • Container spec from devcontainer.json (or default)
# • Per-codespace billing; idle suspension
# 7) Tunnels — connect to your local machine from anywhere
# Lightweight alternative to setting up SSH:
# Cmd/Ctrl+Shift+P → 'Remote-Tunnels: Turn on Remote Tunnel Access...'
# Sign in with GitHub → get a URL like vscode.dev/tunnel/my-name
# Access from any other device's browser or VS Code.
# 8) Performance tips
# • Big repos with many files — exclude node_modules from search/watch:
{
"files.exclude": { "**/node_modules": true, "**/dist": true },
"search.exclude": { "**/node_modules": true, "**/dist": true },
"files.watcherExclude": { "**/node_modules/**": true }
}
# • Disable heavy extensions on remote
# • Use SSH ControlMaster for faster reconnects
# • Codespaces: pick a higher-CPU machine type for heavy builds
# 9) Port forwarding
# Remote-SSH and dev containers auto-forward when a server listens on a port.
# Manually forward: 'Forward a Port' in the Ports panel.
# Set forwardPorts in devcontainer.json so they always show.
# Public visibility (Codespaces) — can share preview URLs.
# 10) File system + git operations on remote
# • Terminal runs on the REMOTE
# • Git uses REMOTE credentials (or forwarded SSH agent)
# • File saves go to REMOTE
# • Drag-drop from local explorer copies via remote workspace
# 11) Common workflows
# • Multiple branches / projects per dev container → context isolation
# • Travel laptop + powerful workstation → SSH into workstation
# • Onboarding → 'Reopen in Container' brings a working dev env in minutes
# • CI consistency → run the same dev container in GitHub Actions
# 12) Security
# • Remote-SSH uses your local SSH config; permissions you have apply
# • Dev containers run as the user defined (remoteUser)
# • Tunnels use GitHub auth — fine for trusted personal use
# • For org policy, restrict tunnel use; use SSO + provisioned containers
# 13) Common bugs
# • 'Could not establish connection to xyz' — check ssh xyz works in plain shell
# • Slow remote on first connect — vscode-server downloading; subsequent connects fast
# • Extension not installing on remote — needs different host CPU arch (musl vs glibc)
# • Port not forwarding — explicit forwardPorts entry; check firewall on remote
# • Dev container build cache miss — use Docker buildx + multi-stage; commit Dockerfile carefully
# • Codespaces idle suspend then long startup — set idle longer or use prebuilds
# • Settings sync clashing with remote settings — settings sync is per-machine; use workspace settings for project rules
# • WSL slow on /mnt/c paths — move code to /home/user
# • Tunnels disconnecting → require GitHub re-auth after 7 days
# • Multiple windows on same host → server prefers one workspace; spawn new window with 'New Window from Remote'
Why it matters
VS Code Remote runs the heavy lifting (language servers, debuggers, terminal) on the remote machine while your local UI stays snappy — SSH for VMs, Dev Containers for reproducible per-project envs, WSL for Windows + Linux tools, Codespaces for cloud-hosted environments, Tunnels for ad-hoc access. Configure forwarded ports, exclude heavy folders from watchers, and split UI vs workspace extensions.
Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.
Example
Example
// Remote — SSH: edit code on a remote machine as if it were local. // Dev Containers: open a project inside a Docker container with all deps preinstalled. // WSL: same for Linux on Windows.Try it Yourself »
Discussion
Loading…