Docker部署code-server

Docker部署code-server

介绍

code-server是一个通过浏览器可以在任何终端设备上进行代码编写的工具,其界面与vscode相似

具体信息可查看GitHub

image-20210819092210120

Docker部署

官方文档中有关于docker部署的命令,这边解释下意义

# This will start a code-server container and expose it at http://127.0.0.1:8080.
# It will also mount your current directory into the container as `/home/coder/project`
# and forward your UID/GID so that all file system operations occur as your user outside
# the container.
#
# Your $HOME/.config is mounted at $HOME/.config within the container to ensure you can
# easily access/modify your code-server config in $HOME/.config/code-server/config.json
# outside the container.
mkdir -p ~/.config
docker run -it --name code-server -p 127.0.0.1:8080:8080 \
  -v "$HOME/.config:/home/coder/.config" \
  -v "$PWD:/home/coder/project" \
  -u "$(id -u):$(id -g)" \
  -e "DOCKER_USER=$USER" \
  codercom/code-server:latest

首先创建自己的配置文件目录

mkdir ~/.config/code-server

然后配置docker运行的端口和挂载目录

docker run -it --name code-server        \
  -p 8081:8080                           \  # 映射主机端口
  # 配置文件目录
  -v "$HOME/.config/code-server:/root/.config/code-server" \
  # 挂载项目目录,使得编写的代码可以在宿主机中找到
  -v "/home/yjs/Project/code-server:/home/coder/project"         \
  -u "$(id -u):$(id -g)"                 \  # 指定用户
  -e "DOCKER_USER=$USER"                 \  # 设置环境
  codercom/code-server:latest               # 镜像名
docker run -it --name code-server        \
  -p 8080:8080                           \
  -v "$HOME/.config/code-server:/root/.config/code-server" \
  -v "/home/yjs/Project/code-server:/home/coder/project"         \
  -u "$(id -u):$(id -g)"                 \
  -e "DOCKER_USER=$USER"                 \
  codercom/code-server:latest

这边在挂载目录下可以看到配置文件

image-20210819101344000

打开即可修改密码,这里先修改为123456

image-20210819101557402

之后重启一下容器

docker restart code-server

完成部署,打开浏览器查看

image-20210819101754792

posted @ 2021-08-19 10:19  骇人的籽  阅读(3071)  评论(0编辑  收藏  举报