FROM codercom/code-server:latest # 设置默认工作区 ENV DEFAULT_WORKSPACE=/home/coder/workspace USER root # 设置时区 RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ echo "Asia/Shanghai" > /etc/timezone # 安装常用工具 RUN apt-get update && \ apt-get install -y \ vim \ htop \ curl \ wget \ git \ zip \ unzip \ jq \ iputils-ping \ python3 \ python3-pip \ sudo && \ rm -rf /var/lib/apt/lists/* # 切换官方市场(使用 jq 向 product.json 追加 extensionsGallery 字段) RUN jq '. += { \ "extensionsGallery": { \ "serviceUrl": "https://marketplace.visualstudio.com/_apis/public/gallery", \ "cacheUrl": "https://vscode.blob.core.windows.net/gallery/index", \ "itemUrl": "https://marketplace.visualstudio.com/items", \ "controlUrl": "", \ "recommendationsUrl": "" \ } \ }' /usr/lib/code-server/lib/vscode/product.json > /tmp/product.json \ && mv /tmp/product.json /usr/lib/code-server/lib/vscode/product.json # 指定 Go 版本号 ARG GO_VERSION=1.25.1 RUN wget -q https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz && \ tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz && \ rm go${GO_VERSION}.linux-amd64.tar.gz USER coder # 将 Go 路径追加到 coder 用户的 .bashrc RUN echo 'export PATH=/usr/local/go/bin:$PATH' >> /home/coder/.bashrc # 安装 nvm + node(使用官方安装脚本) # 注意:必须在 coder 用户下安装 nvm,因为 nvm 是用户级工具 RUN mkdir -p /home/coder/.nvm # 安装 nvm RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash && \ echo 'export NVM_DIR="$HOME/.nvm"' >> /home/coder/.bashrc && \ echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> /home/coder/.bashrc && \ echo '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"' >> /home/coder/.bashrc # 安装最新 LTS Node.js(可选:也可指定版本如 `nvm install 18`) RUN bash -c "source /home/coder/.nvm/nvm.sh && nvm install --lts && nvm alias default node" # 配置 ll 别名 + 启用彩色 ls RUN echo "alias ll='ls -alF'" >> /home/coder/.bashrc && \ echo "alias ls='ls --color=auto'" >> /home/coder/.bashrc # 安装 VS Code 扩展 RUN code-server --install-extension ms-python.python && \ code-server --install-extension golang.go && \ code-server --install-extension tencent-cloud.coding-copilot # 创建默认 README.md RUN mkdir -p "$DEFAULT_WORKSPACE" && \ echo "# 开发环境说明" > "$DEFAULT_WORKSPACE/README.md" && \ echo "" >> "$DEFAULT_WORKSPACE/README.md" && \ echo "本环境已预装以下工具:" >> "$DEFAULT_WORKSPACE/README.md" && \ echo "- **code-server**: Web版 VS Code" >> "$DEFAULT_WORKSPACE/README.md" && \ echo "- **Node.js (LTS)**: 通过 nvm 管理" >> "$DEFAULT_WORKSPACE/README.md" && \ echo "- **Python 3 & pip**" >> "$DEFAULT_WORKSPACE/README.md" && \ echo "- **Go (Golang)**: Go 开发环境" >> "$DEFAULT_WORKSPACE/README.md" && \ echo "- **Git, Vim, curl, wget** 等常用命令行工具" >> "$DEFAULT_WORKSPACE/README.md" && \ echo "" >> "$DEFAULT_WORKSPACE/README.md" && \ echo "时区已设置为 \`Asia/Shanghai\`。" >> "$DEFAULT_WORKSPACE/README.md" # 设置默认打开工作区 WORKDIR $DEFAULT_WORKSPACE EXPOSE 18080 ENTRYPOINT [] CMD ["sh", "-c", "code-server --bind-addr 0.0.0.0:18080 --auth password $DEFAULT_WORKSPACE"]