File size: 3,539 Bytes
f099f9f |
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
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
RUN GO_VERSION=$(curl -s https://go.dev/VERSION?m=text | head -n1) && \
wget -q https://go.dev/dl/${GO_VERSION}.linux-amd64.tar.gz && \
tar -C /usr/local -xzf ${GO_VERSION}.linux-amd64.tar.gz && \
rm ${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 NVM_VERSION=$(curl -s https://api.github.com/repos/nvm-sh/nvm/releases/latest | jq -r .tag_name) && \
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/${NVM_VERSION}/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
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
# 创建默认 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"] |