Docker compose build code server service

Time:2021-12-2

code-server is vscode running on a remote server, accessibale throught the browser.
Code server is a remote vscode that can be built on the server, and we can directly access it with browser. The original intention was to write blog directly in the browser instead of having to open vscode every time. Later, it was found that code server can also be used on iPad, and the compatibility is good
Reference from:https://github.com/cdr/code-s…

X00

The advantage of using docker to build code server is that it can be built quickly, but there is no way to use the environment and configuration of the host. If configuration is required, it needs to be configured from the beginning.

Docker compose is one of the docker official orchestration projects, which is responsible for rapid deployment of distributed applications. Using docker compose, our docker commands can be reused or constitute more advanced configuration files.

to configure

New foldermkdir /usr/local/code-serverIt can be used to store the new project and open the new folder in any locationcd /usr/local/code-server, create and edit docker composetouch docker-compose.yml && vim docker-compose.yml

version: "3"

services:
  code-server:
    container_name: code-server
    image: codercom/code-server
    ports:
      - "8080:8080"
    volumes:
      - "/usr/local/code-server/project:/home/coder/project"
    environment:
      PASSWORD: <password>
    restart: always
  • ports
    The front is the host port, which can be changed to the required port, and the back is the port in the container, which cannot be changed
  • volumes
    Data volume: new folder +’project ‘in front
  • restart
    The container can be restarted automatically after accidental shutdown

Start container

#In the cocker-compose.yml directory

Docker compose up ## starts normally
Docker compose up - D ## background startup

# kill docker container
Docker PS # view the corresponding code server ID
docker kill <id>