File size: 9,184 Bytes
1b781b3 5af2665 a956290 1b781b3 a956290 87f26d3 a956290 87f26d3 43eb65b 87f26d3 f374409 87f26d3 f374409 1795973 87f26d3 5af2665 a956290 1b781b3 aa2d2fd a956290 1b781b3 5af2665 a956290 f374409 1ee4775 f374409 1ee4775 f374409 1ee4775 328f9de 1ee4775 328f9de 1ee4775 a956290 1ee4775 328f9de f374409 1082b0c 2f705a4 1082b0c f374409 1082b0c f374409 2f705a4 f374409 2f705a4 43eb65b 2f705a4 f374409 2f705a4 a956290 1082b0c 1b781b3 5af2665 1082b0c 1b781b3 5af2665 1082b0c 1b781b3 b5baee8 1082b0c 1b781b3 aa2d2fd 1082b0c ac2df60 1082b0c 1b781b3 3f95ec9 1082b0c 1b781b3 3f95ec9 1082b0c 86c4a8d 3b6f751 1082b0c ac2df60 | 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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | FROM ubuntu:22.04
# 设置非交互式安装和时区
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Shanghai
# 安装基础依赖
RUN apt update && apt install -y curl nginx sudo
# 1. 配置时区数据
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# 2. 安装基础依赖和开发工具 (合并步骤减少层数)
RUN apt-get update && apt-get install -y \
tzdata \
curl \
nginx \
sudo \
fakeroot \
fakechroot \
git \
build-essential \
python3 \
python3-pip \
python3-dev \
python3-venv \
python3-setuptools \
python3-wheel \
git-lfs \
jq \
unzip \
zip \
vim \
nano \
wget \
htop \
tmux \
screen \
ca-certificates \
gnupg \
lsb-release \
software-properties-common \
pkg-config \
libssl-dev \
libffi-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
libncurses5-dev \
libncursesw5-dev \
xz-utils \
tk-dev \
libxml2-dev \
libxmlsec1-dev \
liblzma-dev \
# huggingface-cli \
&& rm -rf /var/lib/apt/lists/*
# 3. 创建应用用户并设置权限
RUN useradd -m -u 1000 appuser && \
mkdir -p /var/www/html /var/log/nginx /var/lib/nginx/tmp && \
chown -R appuser:appuser /var/www /var/log/nginx /var/lib/nginx
# 4. 部署 Hello World 前端
RUN echo "<html><body>Hello World</body></html>" > /var/www/html/index.html
# 5. 安装 Node.js (使用 NodeSource 官方源)
RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - && \
apt-get install -y nodejs
# 6. 安装 Python 开发工具和常用包 (HF优化版本,分步安装避免冲突)
RUN pip3 install --no-cache-dir --upgrade pip setuptools wheel
# 6.1 安装基础开发工具
RUN pip3 install --no-cache-dir \
virtualenv \
black \
flake8 \
autopep8 \
isort \
pytest \
requests \
click \
rich \
tqdm
# 6.2 安装数据科学包
RUN pip3 install --no-cache-dir \
numpy \
pandas \
matplotlib
# 6.3 安装基础Web工具(跳过有冲突的包)
RUN pip3 install --no-cache-dir \
pydantic
# 6.4 安装Jupyter相关(避免系统包冲突)
RUN pip3 install --no-cache-dir \
ipython \
jupyter-core \
jupyter-client \
nbformat
# 6.5 安装HuggingFace生态系统
RUN pip3 install --no-cache-dir \
huggingface-hub \
transformers \
datasets
# 注意:跳过以下包以避免blinker冲突:
# - flask (会引起blinker冲突)
# - fastapi (依赖可能冲突)
# - gradio (依赖flask)
# - streamlit (依赖blinker)
# - jupyter (完整版可能冲突)
# 如需使用这些包,可以在容器运行后手动安装
# 7. 安装额外编程语言和工具
# 7.1 安装 Go
RUN wget https://go.dev/dl/go1.21.5.linux-amd64.tar.gz && \
tar -C /usr/local -xzf go1.21.5.linux-amd64.tar.gz && \
rm go1.21.5.linux-amd64.tar.gz
# 7.2 安装 Rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
# 7.3 安装 Deno
RUN curl -fsSL https://deno.land/install.sh | sh
# 7.4 安装 Zig
RUN wget https://ziglang.org/download/0.11.0/zig-linux-x86_64-0.11.0.tar.xz && \
tar -C /usr/local -xf zig-linux-x86_64-0.11.0.tar.xz && \
ln -s /usr/local/zig-linux-x86_64-0.11.0/zig /usr/local/bin/zig && \
rm zig-linux-x86_64-0.11.0.tar.xz
# 7.5 安装 Python 现代工具
RUN pip3 install --no-cache-dir \
ruff \
uv
# 注意:uvx 是 uv 的内置功能,通过 'uv tool run' 或 'uv run' 命令使用
# 7.7 安装 Aria2 下载工具
RUN apt-get update && apt-get install -y aria2 && rm -rf /var/lib/apt/lists/*
# 8. 安装 Node.js 开发工具和常用包 (HF优化版本)
RUN npm install -g \
npm@latest \
yarn \
pnpm \
typescript \
ts-node \
@types/node \
nodemon \
eslint \
prettier \
jest
# 8.1 安装前端框架脚手架工具
RUN npm install -g \
create-react-app \
create-next-app \
@vue/cli \
@angular/cli \
create-vite \
create-nuxt-app \
create-svelte
# 注意:Remix 现在使用不同的安装方式:
# npx create-remix@latest 或 npm create remix@latest
# 8.2 安装构建和开发工具
RUN npm install -g \
vite \
webpack \
webpack-cli \
parcel \
rollup \
turbo \
nx \
lerna
# 9. 安装 VS Code Server (code-server)
RUN curl -fsSL https://code-server.dev/install.sh | sh
# 10. 安装 Cloudflare Tunnel (官方方法)
RUN mkdir -p --mode=0755 /usr/share/keyrings && \
curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null && \
echo 'deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared any main' | tee /etc/apt/sources.list.d/cloudflared.list && \
apt-get update && apt-get install -y cloudflared
# 11. 为应用用户设置权限和环境变量
RUN mkdir -p /home/appuser/.config/code-server && \
mkdir -p /home/appuser/.local/share/code-server && \
chown -R appuser:appuser /home/appuser
# 12. 设置编程语言环境变量
ENV PATH="/usr/local/go/bin:/home/appuser/.cargo/bin:/home/appuser/.deno/bin:${PATH}" \
GOPATH="/home/appuser/go" \
GOROOT="/usr/local/go"
# 13. 复制启动脚本并设置权限
COPY start.sh /start.sh
RUN chmod +x /start.sh
# 14. 复制备份同步脚本并设置权限
COPY backup_sync.sh /backup_sync.sh
RUN chmod +x /backup_sync.sh
# 15. 设置工作目录和用户
WORKDIR /home/appuser
USER appuser
# 16. 设置 HOME 环境变量(关键!)
ENV HOME=/home/appuser
# 17. 配置VSCode扩展市场(启用微软市场)
ENV EXTENSIONS_GALLERY='{"serviceUrl":"https://marketplace.visualstudio.com/_apis/public/gallery","cacheUrl":"https://vscode.blob.core.windows.net/gallery/index","itemUrl":"https://marketplace.visualstudio.com/items"}'
# 18. 安装常用VSCode扩展 (分批安装,避免单个失败影响全部)
# 18.1 核心开发扩展
RUN code-server --install-extension ms-python.python || true && \
code-server --install-extension ms-python.black-formatter || true && \
code-server --install-extension ms-python.pylance || true && \
code-server --install-extension ms-toolsai.jupyter || true
# 18.2 语言支持扩展
RUN code-server --install-extension golang.go || true && \
code-server --install-extension rust-lang.rust-analyzer || true && \
code-server --install-extension denoland.vscode-deno || true && \
code-server --install-extension ziglang.vscode-zig || true
# 18.3 前端开发扩展
RUN code-server --install-extension esbenp.prettier-vscode || true && \
code-server --install-extension dbaeumer.vscode-eslint || true && \
code-server --install-extension bradlc.vscode-tailwindcss || true && \
code-server --install-extension Vue.volar || true
# 18.4 React 和 JavaScript 扩展
RUN code-server --install-extension burkeholland.simple-react-snippets || true && \
code-server --install-extension dsznajder.es7-react-js-snippets || true && \
code-server --install-extension steoates.autoimport-es6-ts || true
# 18.5 CSS 和 HTML 扩展
RUN code-server --install-extension pranaygp.vscode-css-peek || true && \
code-server --install-extension zignd.html-css-class-completion || true && \
code-server --install-extension ecmel.vscode-html-css || true && \
code-server --install-extension formulahendry.auto-rename-tag || true && \
code-server --install-extension formulahendry.auto-close-tag || true
# 18.6 Git 和版本控制扩展
RUN code-server --install-extension eamodio.gitlens || true && \
code-server --install-extension mhutchie.git-graph || true
# 18.7 实用工具扩展
RUN code-server --install-extension christian-kohler.path-intellisense || true && \
code-server --install-extension christian-kohler.npm-intellisense || true && \
code-server --install-extension aaron-bond.better-comments || true && \
code-server --install-extension oderwat.indent-rainbow || true && \
code-server --install-extension gruntfuggly.todo-tree || true && \
code-server --install-extension wayou.vscode-todo-highlight || true && \
code-server --install-extension alefragnani.bookmarks || true
# 18.8 文件格式支持扩展
RUN code-server --install-extension mechatroner.rainbow-csv || true && \
code-server --install-extension redhat.vscode-yaml || true && \
code-server --install-extension jeff-hykin.better-dockerfile-syntax || true
# 注意:移除了以下有问题的扩展:
# - ms-vscode.vscode-json (不存在)
# - ms-vscode.vscode-typescript-next (可能不存在)
# - ritwickdey.liveserver (可能不存在)
# - ms-vscode.vscode-angular (可能不存在)
# - svelte.svelte-vscode (可能不存在)
# - ms-vscode.cmake-tools (可能不存在)
# - twxs.cmake (可能不存在)
# 这些扩展可以在部署后手动安装或使用 fakeroot 安装
# 19. 启动备份同步服务(后台运行)和主应用
CMD sh -c "/backup_sync.sh & /start.sh" |