Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

How to Run code-server on Linux With Docker

Run a browser-based VS Code workspace with persistent files, keep the service on localhost, and connect from another computer over SSH.

Table of Contents

Run code-server in Docker to use a VS Code-style editor in your browser. Bind the service to the Linux host’s loopback address and use an SSH tunnel from another computer. This keeps the editor off public network interfaces while you configure it.

Start the container and keep files on the host

On a Linux host with Docker installed, create directories for settings, editor data and projects. This example uses Bash and the official code-server image. Run it as your normal account with the Docker access already configured on the host.

workspace_dir="$HOME/code-server-workspace"
mkdir -p "$workspace_dir"/{config,local,project}
chmod 700 "$workspace_dir/config"
docker run -d --name code-server 
  -p 127.0.0.1:8443:8080 
  -v "$workspace_dir/config:/home/coder/.config" 
  -v "$workspace_dir/local:/home/coder/.local" 
  -v "$workspace_dir/project:/home/coder/project" 
  -u "$(id -u):$(id -g)" -e "DOCKER_USER=$USER" 
  codercom/code-server:latest

Open http://127.0.0.1:8443 on the Linux host. The generated password is in ~/code-server-workspace/config/code-server/config.yaml. Keep that file private. Use docker logs code-server if the page does not start. The official installation guide also covers options outside Docker.

How to setup web based code server in Linux Picture 1

How to setup web based code server in Linux Picture 2

How to setup web based code server in Linux Picture 3

These screenshots show an earlier container command. Use the loopback binding and mounted directories above. For background on those settings, see the Docker and containers course.

Connect securely from another computer

From a computer that already has authorized SSH access to the Linux host, run ssh -N -L 8443:127.0.0.1:8443 user@linux-host. Replace user@linux-host with your account and hostname. Keep that session open, then visit http://127.0.0.1:8443 on the client. Keep authentication enabled. For other deployment options, follow Coder’s secure access guide.

Open a project and check the editor

In File > Open Folder, open /home/coder/project. Files created there persist in the host’s project directory. Use Explorer to browse, the editor to make changes, and Terminal > New Terminal to run commands in the container.

How to setup web based code server in Linux Picture 4

How to setup web based code server in Linux Picture 5

How to setup web based code server in Linux Picture 6

Use Extensions to install compatible tools from the available catalog. The gear menu opens settings and lets you choose a theme. Check compatibility before assuming a desktop VS Code extension can run on code-server.

How to setup web based code server in Linux Picture 7

How to setup web based code server in Linux Picture 8

How to setup web based code server in Linux Picture 9

How to setup web based code server in Linux Picture 10

How to setup web based code server in Linux Picture 11

Run a test program

Use Explorer to create hello.py in the project folder, save it, and enter this code:

for index in range(3):
    print(f"Hello {index + 1}")

How to setup web based code server in Linux Picture 12

How to setup web based code server in Linux Picture 13

How to setup web based code server in Linux Picture 14

From a terminal in that folder, run python3 hello.py if Python is available. If it is missing, add it to a custom image so it remains available when you recreate the container. Confirm that the terminal prints three lines and that the file appears in the mounted project directory.

How to setup web based code server in Linux Picture 15

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.