This article will guide you on how to use VS Code Server on CDH. If you have a good network environment, you can enjoy VS Code Server in about five minutes.
Writing in the front
When it comes to VS Code Server, we can’t help but think of CDR and Theia. If you are interested in the difference between these two projects, you can browse here: github.com/cdr/code-se… .
In this article, we will use CDR as an example to talk about how to quickly start a VS Code Server application on a CDH device.
Let’s talk about preparation and work.
Preparations: Run the environment
First, let’s talk about the hardware environment. The official recommendation is to run the program with at least 2 cores of 1GB of resources. This demo runs on the DS920+ mentioned in the previous article, with 4 cores on the CPU and 12GB of ram. I suspect that environments with DS720+ or similar configurations can also be enjoyable to play with. Virtual machine main frequency is higher, the problem should be less, although it is not recommended to use black group hui, but if you must experience it, it is theoretically possible 🙂
As you can see in “Kit Center”, the Docker version I’m using is 18.09.8.
SSH login to the system, you can see the more detailed build version, if your CDH system is DSM 6 or above, then you should not bother, if it is lower than this version (DSM5), there may be some problems, please upgrade yourself.
soulteary@Lemon:~$docker -v docker version 18.09.8, build bfed4f5Copy the code
In order to ensure the data security after the software runs, we need to do some extra preparations.
Preparations: User rights
To ensure that user permissions are normal during the software operation, no “insufficient permission error” is reported after the software is started, and data is private to avoid being read and modified by other users or programs. Before we officially run the environment, we need to do some permission-related preparation and simple setup.
Log in to the qunhui Web interface, create a directory named “CDR” under the container running directory to store the container configuration files, and create two directories named “VScode” and “project” in the personal home directory to store vscode configuration and project files and data later.
If you’re comfortable using the command line, it’s easy to create a directory. After SSH to the device, run the command as the normal user you plan to use (volume1 needs to be replaced with the actual partition) :
mkdir -p /volume1/homes/soulteary/vscode
mkdir -p /volume1/homes/soulteary/projects
mkdir -p /volume1/docker/cdr
Copy the code
Then look at the UID and GID of the user on the system (for example, user soulteary) :
# cat /etc/passwd | grep soulteary
soulteary:x:1026:100::/var/services/homes/soulteary:/bin/sh
Copy the code
Write down 1026:100 for later use.
Write a container configuration file
Then save the following configuration as docker-comemage.yml and place it in the “CDR” directory we prepared above.
version: "3"
services:
cdr:
image: Codercom/code - server: 3.10.2
container_name: cdr
restart: always
expose:
- 8080
ports:
- 8080: 8080
user: 1026: 100
environment:
- TZ=Asia/Shanghai
- DOCKER_USER=soulteary
volumes:
- /etc/localtime:/etc/localtime:ro
- /volume1/homes/soulteary/vscode:/home/coder/.config:rw
- /volume1/homes/soulteary/projects:/home/coder/project:rw
logging:
driver: "json-file"
options:
max-size: "1m"
Copy the code
In particular, you need to set both user: 1026:100 and the environment variable DOCKER_USER=soulteary to give VS Code Server proper file read and write permissions.
To ensure that the time zone is normal during software running, file creation time, application log printing time, and program dependent time calculation results are normal, you can also specify the time zone variable TZ=Asia/Shanghai for the application.
If you do not want the configuration file to be associated with the logical volume of the cluster disk, you can also save the configuration file in the home directory and change the volume in the configuration to a relative directory:
volumes:
- /etc/localtime:/etc/localtime:ro
- ./vscode:/home/coder/.config:rw
- ./projects:/home/coder/project:rw
Copy the code
Once ready, we started the application with docker-compose up -d and used docker-compose logs -f to view the logs of the application startup process.
Creating cdr ... The done Attaching to the CDR CDR | [the 2021-06-14 T00:59:58. 662 z] info demonstrate the default config file to . ~ / config/code - server/config. Yaml CDR | [the 2021-06-14 T00:59:59. 226 z] info code - server 3.10.2 2021-06-14, 387 b12ef4ca404ffd39d84834e1f0776e9e3c005 CDR | T00:59:59. 228 z] info Using user data -- dir . ~ / local/share/code - server CDR | [the 2021-06-14 T00:59:59. 249 z] info Using the config file ~ /. Config/code - server/config. Yaml CDR | [the 2021-06-14 T00:59:59. 249 z] HTTP server listening on http://0.0.0.0:8080 info CDR | [the 2021-06-14 T00:59:59. 249 z] info - Authentication is enabled the CDR | [the 2021-06-14 T00:59:59. 249 z] info - Using the password from ~ / config/code - server/config. Yaml CDR | [the 2021-06-14 T00:59:59. 250 z] info - Not serving HTTPSCopy the code
Unsurprisingly, you’ll see something like the log above, then use your browser to access port 8080 that we declared in the configuration file to start your VSCode Server experience.
Using VSCode Server
We use qunhui device IP and port 8080 to access VSCode Server, the first login will see the need to enter the password.
This password is saved in the config.yaml configuration file in the “vscode” directory that we created in the preparation steps.
Using your preferred method, open the configuration file and see something like the following.
Bind-addr: 127.0.0.1:8080 auth: password password: e0409d8C5302a6a5da0b18b0 cert: falseCopy the code
Login with password screen, you can see the familiar VSCode welcome screen.
Next, install the plug-in and personalize it. I’ll leave it to you to explore.
The last
Originally planned to talk about Nginx module related tips, see the group of students have questions about the group hui run container application, so I first wrote this article.
–EOF
We have a little group of people who like to do things.
In the case of no advertisement, we will talk about software and hardware, HomeLab and programming problems together, and also share some information of technical salon irregularly in the group.
Like to toss small partners welcome to scan code to add friends. (Please indicate the source and purpose, and note the real name, otherwise it will not pass the audit)
All this stuff about getting into groups
If you think the content is still practical, welcome to share it with your friends. Thank you.
This article is published under a SIGNATURE 4.0 International (CC BY 4.0) license. Signature 4.0 International (CC BY 4.0)
Author: Su Yang
Creation time: on June 14, 2021 statistical word count: 3704 words reading time: 8 minutes to read this article links: soulteary.com/2021/06/14/…