Skip to content

Visual Studio Code Server container setup

Introduction

Code-server is Visual Studio Code running on a remote server, accessible through the browser. Since I use Visual Code Server to edit yaml files of Home Assistant I have created a volume mapping to the config folder of Home Assistant.

Setup

  1. Create the folders needed by the container

    Run the following commands inside your home folder:

    # Open your terminal application
    cd ~
    mkdir -p codeserver/config
    cd codeserver
  2. Create the script needed to run the container

    Save the following script as codeserver_run.sh:

    codeserver_run.sh
    # To create this script use your text editor application, for example Nano
    IDu=$(id -u $(logname)) # Saves the logged in user id in the IDu variable
    IDg=$(id -g $(logname)) # Saves the logged in user group in the IDg variable
    docker run -d \
    --name=codeserver \
    --hostname=codeserver \
    -p 8833:8443 \
    -v $PWD/config:/config \
    -v /home/<linux-username>/homeassistant/config:/homeassistant \
    -v /etc/localtime:/etc/localtime:ro \
    -e PUID=$IDu \
    -e PGID=$IDg \
    -e TZ=Europe/Amsterdam \
    --restart unless-stopped \
    linuxserver/code-server
    # IMPORTANT: Please read the instructions below
    Instructions:
    • Optional Replace docker with podman if needed
    • Required Replace port number 8833 (on the left side of :) with a port number that is available if needed.
    • Optional Replace $PWD/config with the location of your configuration if needed. This can be a fileserver mount
    • Required Replace <linux-username> with your own username if you want to create a mapping to a location with files you want to edit with code server. In this example it is the configuration folder of Home Assistant. This will only work if this container is on the same machine as your Home Assistant instance. So you can remove the whole line if you do not use this mapping
    • Required Replace Europe/Amsterdam with your own timezone
  3. Run the script to create the container

    Run the following command:

    # Open your terminal application
    sudo sh codeserver_run.sh

    The image linuxserver/code-server is automatically pulled and the container is created.

  4. Check the results

    If needed you can check if the container is running properly.

    Now you can use Visual Studio Code Server by opening a web browser and going to: http://localhost:8833. Replace localhost with the relevant IP address or FQDN if needed, and adjust the port if you changed it earlier.

    To use the mapping to the Home Assistant configuration map go to File and Open Folder..., empty the command palette and type /homeassistant and press Enter. Now it is possible to edit the yaml files of Home Assistant.

Favorites

Comments

    No comments found for this note.

    Join the discussion for this note on Github. Comments appear on this page instantly.

    Copyright 2021- Fiction Becomes Fact