code-server 是开源的在浏览器中运行 VS Code。如果你想搭建一套自己的远程开发环境 code-server
是一个不错的选择。如果只是给自己用 code-server
没什么问题,如果想提供团队使用就得配合 Coder 来做用户和环境等管理。
下面是 Coder 使用过程中遇到问题的一些简单记录。
Docker 镜像拉取问题
在国内拉取 Docker 镜像几乎无法成功,如果使用 Docker 部署首先要修改 Docker 源。
Linux 下 Docker 的配置文件位于 /etc/docker/daemon.json
。修改 Docker 源的方法网上有很多资料,这里不再赘述。
为 Coder 设置代理
Coder 创建 Template 时需要从网络上下载资料,这一步很容易失败。通过环境变量的方式为 Coder 设置代理 HTTP_PROXY 和 HTTPS_PROXY
。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | services: coder: # This MUST be stable for our documentation and # other automations. image: ghcr.io/coder/coder : $ { CODER_VERSION : -latest } ports: - "7080:7080" environment: CODER_PG_CONNECTION_URL: "postgresql://${POSTGRES_USER:-username}:${POSTGRES_PASSWORD:-password}@database/${POSTGRES_DB:-coder}?sslmode=disable" CODER_HTTP_ADDRESS: "0.0.0.0:7080" # You'll need to set CODER_ACCESS_URL to an IP or domain # that workspaces can reach. This cannot be localhost # or 127.0.0.1 for non-Docker templates! # CODER_ACCESS_URL: "${CODER_ACCESS_URL}" group_add: - "124" # docker group on host `getent group docker | cut -d: -f3` user: "1000:1000" volumes: - /var/run/docker .sock: /var/run/docker.sock - ./coder_home : /home/coder depends_on: database: condition: service_healthy database: image: "docker.1ms.run/postgres:16" environment: POSTGRES_USER: $ { POSTGRES_USER : -username } # The PostgreSQL user (useful to connect to the database) POSTGRES_PASSWORD: $ { POSTGRES_PASSWORD : -password } # The PostgreSQL password (useful to connect to the database) POSTGRES_DB: $ { POSTGRES_DB : -coder } # The PostgreSQL default database (automatically created at first launch) volumes: - ./coder_data : /var/lib/postgresql/data # Use "docker volume rm coder_coder_data" to reset Coder healthcheck: test: [ "CMD-SHELL" , "pg_isready -U ${POSTGRES_USER:-username} -d ${POSTGRES_DB:-coder}" , ] interval: 5s timeout: 5s retries: 5 |
编辑 Template
在 Template 中设置代理
通过 Template 创建 Workspace 依旧会用到网络,这一步依旧很难成功。在 resource "coder_agent" "main"
中添加 HTTP_PROXY
和 HTTPS_PROXY
。
Docker in Docker
如果要在 Workspace 中调用 Docker,需要将 docker.sock
映射给 workspace,且需要将传入的路径转换为 HOST 的文件路径。还需要将 HOST 的 docker 用户组添加给 coder 用户。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # ... resource "coder_agent" "main" { # ... env = { # ... HTTP_PROXY = "http://your-proxy.com:1087" HTTPS_PROXY = "http://your-proxy.com:1087" } # ... } resource "docker_container" "workspace" { # ... group_add = ["124"] # host 的 docker 用户组id # unsafe, should https://coder.com/docs/v2/latest/templates/docker-in-workspaces#use-sysbox-in-docker-based-templates volumes { host_path = "/var/run/docker.sock" container_path = "/var/run/docker.sock" } # ... } |
禁用 autostop
为节约服务器资源,长期不用的 workspace 会被自动销毁,下次使用时再进行重建。如果服务用的人不多,资源足够,建议把 autostop 关闭掉。
选中 template 并进入 template 的 settings 并在 schedule 中将 default autostop 修改为 0。