---
title: 'VS Code Server'
url: 'https://www.handtrixxx.com/en/wiki/free-open-source-software/vs-code-server'
markdown: 'https://www.handtrixxx.com/en/wiki/free-open-source-software/vs-code-server.md'
lang: en
date: '2023-04-22'
description: "VS Code Server Microsoft's Visual Studio Code has established itself over the last years as a quasi-standard – not only for editing source code in all possible (programming) languages, but also for a multitude of further operations. One of the points of criticism remains the relatively high system…"
---

#  VS Code Server 

Microsoft's [Visual Studio Code](https://code.visualstudio.com/) has established itself over the last years as a quasi-standard – not only for editing source code in all possible (programming) languages, but also for a multitude of further operations.

![](https://www.handtrixxx.com/user/pages/wiki/free-open-source-software/vs-code-server/01-vscode.png)

One of the points of criticism remains the relatively high system load caused by the editor, which is justified indeed, but for a "text editor" nevertheless appears somewhat peculiar. Another point of criticism is that for the popular "Remote SSH" plugin, which enables working on any server reachable via SSH with VS Code, quite many dynamic ports are opened, and generally some firewalls can make problems here.

Now VS Code itself is based on the [Electron framework](https://en.wikipedia.org/wiki/Visual_Studio_Code), which in turn builds on JavaScript. So why not host the VS Code installation on a server and provide it via a web interface? Obviously many have asked themselves that, and therefore this is quickly accomplished with the help of Docker and Caddy.

## Installation

For the installation we again rely on Docker Compose for the management of our containers and Caddy as reverse proxy. A fitting and regularly updated VS Code image we find from [Linuxserver.io](http://Linuxserver.io) on [Docker Hub](https://hub.docker.com/r/linuxserver/code-server).

Our "compose.yml" file can then look like this:

```yaml
---
version: "2.1"
services:
  code-server:
    image: lscr.io/linuxserver/code-server:latest
    container_name: code-server
    environment:
      - PUID=1001
      - PGID=1001
      - TZ=Etc/UTC
      - PASSWORD=YOURPASSWORD
      #- HASHED_PASSWORD=#optional
      #- SUDO_PASSWORD=#optional
      #- SUDO_PASSWORD_HASH=#optional
      #- PROXY_DOMAIN=#optional
      - DEFAULT_WORKSPACE=FOLDERCONTAINER #optional
    volumes:
      - ./config:/config
      - /HOSTFOLDER:/FOLDERCONTAINER
    restart: unless-stopped
    logging:
      options:
        max-size: "10m"
        max-file: "3"
    networks:
        - caddy

volumes:
    data:
    db:
networks:
    caddy:
        external: true
```

The most important parameters here briefly explained:

- environment – PUID: The process ID that should as much as possible correspond to the ID of your user, so that later you can get out of the way of permission problems when editing files. You simply get your own ID via the Linux command line with the command "id".
- environment – PGID: The same as for the PUID, only that here the group ID is meant.
- environment – PASSWORD: The password that is asked for when one calls up the container's URL. Since not even a user is set, that is not particularly safe, and an additional level of security should be created, e.g. via the reverse proxy. See chapter "Hardening".
- environment – SUDO\_PASSWORD: Here the sudo password for the container can be set. As far as possible this should be avoided, since in a container according to security best practices one should never work as root.
- environment – HASHED\_PASSWORD and SUDO\_PASSWORD\_HASH: Both parameters should help that no passwords have to be stored in plaintext in the "docker-compose.yml". How one generates such a hash value is explained on the project page, but at least for me it did not work that way. Also therefore an additional "hardening" as described below is required.
- environment – DEFAULT\_WORKSPACE: Here we specify the path on the container that is specified below under volumes. We then see this as workspace/folder in VS Code.
- volumes – /HOSTFOLDER:/FOLDERCONTAINER: If desired we can specify here a path on our host(server) that appears in VS Code. The variable FOLDERCONTAINER we in turn replace by the value that we specified as "DEFAULT\_WORKSPACE".

Now we can start the container with "docker compose up -d".

## Hardening and reverse proxy configuration

In our Caddyfile of our reverse proxy we add a block for the new VS Code instance. That can look like this:

```caddyfile
code.handtrixxx.com {
    basicauth {
        USER HASHVALUE
    }
    reverse_proxy code-server:8443
}
```

Note the values in the curly brackets behind "basicauth". These bring additional protection against possible attackers, in that they provide a further authentication as soon as someone opens the URL. As USER you can define a name of your choice; for generating the hash value one switches on the command line into the Docker Compose folder of Caddy and executes the following command there: `docker compose exec -w /etc/caddy caddy caddy hash-password`

The value resulting from the query you simply copy as HASHVALUE into the Caddyfile.

After we have reloaded the configuration of Caddy, VS Code is reachable under the specified URL and the additional security layer is activated.

---

## Navigation

- Parent: [Free Open-Source Software](https://www.handtrixxx.com/en/wiki/free-open-source-software.md)
- Previous: [Outline](https://www.handtrixxx.com/en/wiki/free-open-source-software/outline.md)
- Next: [WordPress](https://www.handtrixxx.com/en/wiki/free-open-source-software/wordpress.md)
