Code-Server – VS Code on Docker

In this tutorial, you’ll be learning how to setup Code-Server – VS Code on Docker

What is Code-Server and Why Code-Server ?

  • Code-Server is a VS Code instance running on Docker accessible via a browser
  • It can be run on a powerful remote server to keep the load off your system
  • All intensive computation will run on the Docker container deployed on the remote server
  • It is lightweight, open source and free to use
  • It can be deployed and managed easily with Docker and Docker-Compose

Read more here: https://github.com/linuxserver/docker-code-server

For more blogs, visit: Blogs
For Docker related Blogs, visit: Docker

Pre-requisites

Steps to Deploy Code-Server on Docker

1. Create a directory and a docker-compose yaml file for the project

# Create a directory for the project
mkdir code-server
# Navigate into the directory
cd code-server
# Create a docker compose yaml file
touch docker-compose.yml
# Create a directory to store container config
mkdir config

2. Add the configuration to the yaml file as shown

# Get the UID and GID of the user to run the container
echo $(id -u) # UID
echo $(id -g) # GID

# Paste the below content into the docker-compose.yaml file
---
version: "2.1"
services:
  code-server:
    image: lscr.io/linuxserver/code-server
    container_name: code-server
    environment:
      - PUID=1000 # Use the UID from the command mentioned above
      - PGID=100 # Use the GID from the command mentioned above
      - TZ=Asia/Kolkata # Time Zone of your choice for the container
      - PASSWORD=password # Login password for the Web UI
      - SUDO_PASSWORD=password # Sudo password (Optional)
    volumes:
      - /home/pi/code-server/config:/config # Volume mount for the container config files (Replace the path with the path on your host)
    ports:
      - 8443:8443 # Port mapping for the container in the format <host-port>:<container-port>. You can choose the <host-port> as per your convenience 
    restart: unless-stopped # Keep the container running unless manually stopped

3. Browse to http://<ip>:<port> to access the installation. You should be able to see the dashboard as shown below. Enter your password and login

Code-server

4. You should now be able to see your VS code instance

Code-server

5. Let us now create a simple docker-compose.yaml file and store it using VS code. Create a file by using the New File option in the File menu as shown below

Code-server

6. Add the contents to the file and save the file by using the Save option in the File menu. The path for the file exists within the workspace directory present in the config directory which has been mounted to the host previously

Code-server

7. We have now created and saved the file on our server

Code-server

Congratulations!! You have successfully deployed Code-Server on Docker

5733cookie-checkCode-Server – VS Code on Docker

3 Comments

  1. Avatar graliontorile

    Way cool, some valid points! I appreciate you making this article available, the rest of the site is also high quality. Have a fun.

  2. Hey, great tutorial!
    I am using code-server on a Raspberry Pi in a Docker environment. Is it possible to define my DEFAULT_WORKSPACE to access the local root directory of my Raspberry?
    I have tried to use the following
    Environment:
    – DEFAULT_WORKSPACE=/home/pi/share # outside the container
    Volumes:
    – /home/pi/share/vs-code/config:/config # (works as intended).
    – /home/pi/share:/config/workspace # possibly unnecessary
    but I only have access to my root folder inside the container.

    • Hey there!!
      This might be because the PUID and PGID that you have specified in the docker-compose file might not be of the root user
      Try changing that to the root user and you probably will be able to access the root folder
      Thanks

Leave a Comment

Your email address will not be published. Required fields are marked *