Technical Tutorials
Deploy an Online Code Editor on a VPS (2025) - Complete Code-server Installation Guide
A complete guide to deploying Code-server on a VPS in 2025. Docker containerized deployment, Caddy reverse proxy with automatic HTTPS, and security hardening so you can write code in your browser anytime, anywhere.

Want to write code on a tablet? Want to access your development environment anytime, anywhere? Code-server can help you move VS Code to the cloud and access it anytime through a browser—no software installation required, just an internet connection and you can code.
This article will walk you through deploying Code-server on a VPS step by step, including Docker containerized deployment, HTTPS security configuration, and best practices for multi-user scenarios.
Code-server is an open-source project by Coder that runs the full Visual Studio Code in your browser. Unlike the official vscode.dev, Code-server runs on your own server and offers the following advantages:
- Full terminal access: Operate the server command line directly in the browser
- Persistent workspace: Code and configuration are saved on the server, so you can seamlessly continue on another device
- Full plugin support: Install any VS Code plugin
- Unlimited resources: Leverage server compute power, so even low-spec computers can run large projects
- Controllable privacy: Data is stored on your own VPS
| Configuration | Minimum | Recommended |
|---|---|---|
| CPU | 1 core | 2 cores |
| Memory | 1GB | 2GB+ |
| Storage | 10GB | 20GB+ SSD |
| OS | Ubuntu 20.04+ / Debian 11+ | Ubuntu 22.04 LTS |
Make sure Docker and Docker Compose are installed on the VPS:
# 安装 Docker (如果还没装)
curl -fsSL https://get.docker.com | sh
sudo systemctl enable --now docker
# 验证安装
docker --version
docker compose version
Before starting deployment, make sure the following ports are allowed in the VPS firewall or cloud provider security group:
- 80 (TCP): Let's Encrypt certificate validation
- 443 (TCP): HTTPS access
# UFW 示例
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw reload
Note: If you use a domestic provider such as Alibaba Cloud or Tencent Cloud, you also need to add rules in the console's "Security Group".
Deploying with Docker is the most hassle-free approach: one command handles dependencies and isolation.
mkdir -p ~/code-server/{config,workspace}
cd ~/code-server
version: "3.8"
services:
code-server:
image: codercom/code-server:latest
container_name: code-server
restart: unless-stopped
ports:
- "127.0.0.1:8443:8080" # 只绑定本地,通过反向代理暴露
environment:
- PASSWORD=YourStrongPassword123! # 修改为强密码
- TZ=Asia/Shanghai
volumes:
- ./config:/home/coder/.config
- ./workspace:/home/coder/project
user: "1000:1000" # 使用非 root 用户
Security tip: Binding the port to
127.0.0.1is key! This prevents Code-server from being directly exposed to the public internet; all traffic must go through the reverse proxy.
docker compose up -d
Code-server is now running on local port 8443, but it is not yet accessible from outside. The next step is to configure HTTPS.
We use Caddy as the reverse proxy; it automatically requests and renews Let's Encrypt certificates.
# Debian/Ubuntu
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy
Go to Cloudflare (or your DNS provider) and add an A record:
类型: A
名称: code
值: 你的 VPS IP
代理状态: 仅 DNS(灰色云朵) # 重要!SSL 由 Caddy 处理
Verify that DNS is in effect (you must confirm this before starting Caddy):
dig code.yourdomain.com +short
# 应该返回你的 VPS IP 地址
If no IP is returned, wait for DNS to take effect (usually a few minutes), otherwise the SSL certificate request will fail.
Edit /etc/caddy/Caddyfile:
code.yourdomain.com {
reverse_proxy 127.0.0.1:8443
# 可选:添加基础认证双重保护
# basicauth {
# admin $2a$14$... # caddy hash-password 生成的 bcrypt
# }
}
sudo systemctl enable --now caddy
sudo systemctl reload caddy
After a few seconds, visit https://code.yourdomain.com and you will see the VS Code login screen! Enter the password set in docker-compose.yml to log in.
A cloud code editor exposed to the public internet makes security configuration critical:
Set a complex password of at least 16 characters in docker-compose.yml, including uppercase and lowercase letters, numbers, and special characters.
sudo apt install fail2ban -y
Create /etc/fail2ban/jail.local:
[code-server]
enabled = true
port = http,https
filter = code-server
logpath = /var/log/caddy/access.log
maxretry = 5
bantime = 3600
cd ~/code-server
docker compose pull
docker compose up -d
If you only access the server through Code-server, you can disable SSH password login and allow only key authentication.
Your code and configuration are stored in the ~/code-server directory. Be sure to back up this directory regularly! If the VPS fails or you accidentally delete it, all your work will be lost.
tar -czvf code-server-backup-$(date +%Y%m%d).tar.gz ~/code-server
We recommend using Rclone to sync to cloud storage (S3/OneDrive/Google Drive). See: VPS automated backup solutions
If multiple people share one server, you can create a separate container for each user:
services:
alice:
image: codercom/code-server:latest
ports:
- "127.0.0.1:8444:8080"
volumes:
- ./alice:/home/coder
environment:
- PASSWORD=AlicePassword
bob:
image: codercom/code-server:latest
ports:
- "127.0.0.1:8445:8080"
volumes:
- ./bob:/home/coder
environment:
- PASSWORD=BobPassword
Then configure different subdomains in the Caddyfile to point to different ports.
After entering Code-server, press Ctrl+Shift+X to open the plugin marketplace. Recommended plugins:
- Python / Go / Rust Analyzer - Language support
- GitLens - Git enhancements
- Remote - SSH - Remote development (if you need to connect to other servers)
- Docker - Container management
- Make sure the VPS is in a low-latency region (such as Hong Kong or Japan)
- Upgrade to 2 cores and 2GB or more
- Use Cloudflare's Argo Tunnel to optimize the connection
- Check whether DNS resolution is in effect:
dig code.yourdomain.com +short - Make sure port 80 is open (required by Let's Encrypt)
- Cloudflare proxy must be turned off (gray cloud)
Yes, but note:
- The domain needs ICP filing
- Apply for the SSL certificate yourself (domestic providers may not support automation)
Code-server truly makes your development environment "cloud-based". With a stable VPS, you can write code on any device—whether an iPad, a Chromebook, or a computer in an internet cafe—just by opening a browser.
Recommended configuration: A VPS with 2 cores and 2GB or more, paired with a low-latency Asian data center (Hong Kong/Japan/Singapore), for the best experience.
Deploy your cloud VS Code now!