Skip to content
hero
Philippe Bordron

How to use code-server on the cluster

Code-server on compute node diagram

Code-server is a version of VSCode designed to run in your web browser like the one available on the institutional forge. Here we will run code-server on a compute node and access it by using an SSH tunnel.

This tutorial is based on cluster How-to documentation.

Configure (once)

Connect to the cluster, and run code-server to create config files in ~/.config/code-server. During this step, you need to hit Ctrl+C to stop code-server when it display Session server listening on ...

# Connect to the cluster (replace <my-login> by your own login)ssh <my-login>@genobioinfo.toulouse.inrae.fr# Run an interactive jobsrun --pty bash# Run code-servermodule load tools/code-server/4.96.4code-server --disable-telemetry[...] info Wrote default config file to /home/<user>/.config/code-server/config.yaml
[...] info code-server 4.96.4 b7ef8f9bd70cb5b342fa8ec8a0086bad676d8124
[...] info Using user-data-dir /home/<user>/.local/share/code-server
[...] info Using config file /home/<user>/.config/code-server/config.yaml
[...] info HTTP server listening on http://127.0.0.1:8080/
[...] info - Authentication is enabled
[...] info - Using password from /home/<user>/.config/code-server/config.yaml
[...] info - Not serving HTTPS
[...] info Session server listening on /home/<user>/.local/share/code-server/code-server-ipc.sock
^C

Then edit the file ~/.config/code-server/config.yaml:

~/.config/code-server/config.yaml
1
2
3
4
5
6
bind-addr: 0.0.0.0:8888 # (1)!
auth: password
password: <random password> # (2)!
cert: false
disable-telemetry: true # (3)!
locale: fr # (4)!
  1. By setting 0.0.0.0 instead of 127.0.0.1, you can connect to code-server from another machine. We recommend to change the default port 8080 by another one between 1024 and 65535. You will avoid collision with other user this way. Here we set it to 8888.
  2. You can change the password. Replace the <random password> by what you want.
  3. Disable telemetry (optional)
  4. Set your interface language (optional)

Use code-server

There is two main steps:

  1. Run code-server on a compute node,
  2. Connect to it with your web browser by using a ssh tunnel.

Run code-server

# Connect to the cluster (replace <my-login> by your own login)ssh <my-login>@genobioinfo.toulouse.inrae.fr# Run an interactive job for code-server# (adapt memory and cpus reservation to yours needs)srun --mem 4G --cpus-per-task 2 --pty bash# We get the name of the compute node the job run on. We need it in next step.hostnamen001# Run code-server (with default parameters set in config.yaml)module load tools/code-server/4.96.4code-server...
# Alternatively, you can change some parameters (`code-server -h`)# Here we run code-server on port 8989 without password protection code-server --bind-addr 0.0.0.0:8989 --auth none ...

You can get code-server options by looking at code-server documentation or by using its help command code-server -h

Connect to code-server

In order to connect to code-server, we need to create a ssh tunnel like in OOD tutorial.

From previous step, we know that code-server runs on node n001 and listen on port 8989.

We open a new terminal on our computer and start a second ssh connection following the command template ssh -N -L <local-port>:<nodename>:<remote-port> <my-login>@genobioinfo.toulouse.inrae.fr:

# Connect to the cluster (replace <my-login> by your own login)# Here# - <local-port>=8080# - <nodename>=n001# - <remote-port>=8989ssh -N -L 8080:n001:8989 <my-login>@genobioinfo.toulouse.inrae.fr# The command gives the impression to never finish and it is something normal.

You can stop it by hitting the Ctrl+C combination. If you stop it by mistake, run the command again.

Now open your browser and go to url http://127.0.0.1:<local-port>. In our example it is http://127.0.0.1:8080. Enter the password set in the config.yaml or set in your code-server command.

Stop everything

  • In the terminal where the code-server is running, hit Ctrl+C and then stop your interactive job (srun) with exit command or Ctrl+D.
  • In the terminal where you create the tunnel, hit Ctrl+C .