Add code-server variant as Dockerfile.cnb
Create Dockerfile.cnb based on the optimized Dockerfile with code-server v4.123.0 + 10 VS Code extensions (golang, cnb-welcome, code-runner, kubernetes, coding-copilot, github-theme, zh-hans-langpack, vscode-icons, indent-rainbow, markdown-all-in-one). Constraint: extensions install as user to ~/.local, then switch back to root Confidence: high Scope-risk: narrow Tested: docker build succeeded, all 10 extensions installed OK
Showing
1 changed file
with
147 additions
and
0 deletions
container/Dockerfile.cnb
0 → 100644
| 1 | # syntax=docker/dockerfile:1 | ||
| 2 | # ================================================================ | ||
| 3 | # Multi-stage build for minimal container image | ||
| 4 | # Uses COPY technique: builder stage downloads + extracts, | ||
| 5 | # final stage only copies runtime artifacts. | ||
| 6 | # ================================================================ | ||
| 7 | |||
| 8 | # ---- Stage 1: Builder (downloads + extracts) ---- | ||
| 9 | FROM debian:13.4-slim AS builder | ||
| 10 | |||
| 11 | RUN apt-get update && \ | ||
| 12 | apt-get install -y --no-install-recommends \ | ||
| 13 | ca-certificates curl unzip && \ | ||
| 14 | rm -rf /var/lib/apt/lists/* | ||
| 15 | |||
| 16 | # Python (Miniconda) | ||
| 17 | RUN curl -sSLk https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py310_23.11.0-2-Linux-x86_64.sh \ | ||
| 18 | -o /tmp/miniconda.sh && \ | ||
| 19 | bash /tmp/miniconda.sh -b -p /usr/local/miniconda3 && \ | ||
| 20 | rm /tmp/miniconda.sh && \ | ||
| 21 | /usr/local/miniconda3/bin/conda clean -a -y | ||
| 22 | |||
| 23 | # Node.js (prebuilt binary, no build tools needed) | ||
| 24 | RUN curl -sSLk https://unofficial-builds.nodejs.org/download/release/v22.22.2/node-v22.22.2-linux-x64-glibc-217.tar.gz \ | ||
| 25 | -o /tmp/node.tar.gz && \ | ||
| 26 | tar -xzf /tmp/node.tar.gz -C /usr/local/ && \ | ||
| 27 | rm /tmp/node.tar.gz && \ | ||
| 28 | ln -sf /usr/local/node-v22.22.2-linux-x64-glibc-217/bin/node /usr/local/bin/node && \ | ||
| 29 | ln -sf /usr/local/node-v22.22.2-linux-x64-glibc-217/bin/npm /usr/local/bin/npm | ||
| 30 | |||
| 31 | # Bun | ||
| 32 | RUN curl -fsSL https://bun.sh/install | BUN_INSTALL=/usr/local/bun bash | ||
| 33 | |||
| 34 | # opencode-ai + strip unnecessary platform binaries | ||
| 35 | RUN npm i -g opencode-ai --registry https://mirrors.cloud.tencent.com/npm/ && \ | ||
| 36 | rm -rf /usr/local/node-v22.22.2-linux-x64-glibc-217/lib/node_modules/opencode-ai/node_modules/opencode-linux-x64-musl && \ | ||
| 37 | rm -rf /usr/local/node-v22.22.2-linux-x64-glibc-217/lib/node_modules/opencode-ai/node_modules/opencode-linux-x64-baseline && \ | ||
| 38 | rm -rf /usr/local/node-v22.22.2-linux-x64-glibc-217/lib/node_modules/opencode-ai/node_modules/opencode-linux-x64-baseline-musl && \ | ||
| 39 | npm cache clean --force | ||
| 40 | |||
| 41 | # ---- Stage 2: Minimal final image ---- | ||
| 42 | FROM debian:13.4-slim | ||
| 43 | |||
| 44 | # Mirror (China mainland) | ||
| 45 | RUN sed -i 's/deb.debian.org/mirrors.tencent.com/g' /etc/apt/sources.list.d/debian.sources | ||
| 46 | |||
| 47 | # System packages + Claude Code (single RUN layer for minimal size) | ||
| 48 | RUN apt-get update && \ | ||
| 49 | apt-get install -y --no-install-recommends \ | ||
| 50 | ca-certificates curl wget unzip \ | ||
| 51 | git git-lfs \ | ||
| 52 | zsh tmux \ | ||
| 53 | ripgrep jq sudo \ | ||
| 54 | vim \ | ||
| 55 | tzdata locales \ | ||
| 56 | lsof nload htop net-tools dnsutils \ | ||
| 57 | openssh-server && \ | ||
| 58 | # Claude Code official apt repo | ||
| 59 | install -d -m 0755 /etc/apt/keyrings && \ | ||
| 60 | curl -fsSL https://downloads.claude.ai/keys/claude-code.asc \ | ||
| 61 | -o /etc/apt/keyrings/claude-code.asc && \ | ||
| 62 | chmod a+r /etc/apt/keyrings/claude-code.asc && \ | ||
| 63 | echo "deb [signed-by=/etc/apt/keyrings/claude-code.asc] https://downloads.claude.ai/claude-code/apt/stable stable main" \ | ||
| 64 | > /etc/apt/sources.list.d/claude-code.list && \ | ||
| 65 | apt-get update && \ | ||
| 66 | apt-get install -y --no-install-recommends claude-code && \ | ||
| 67 | apt-get clean && \ | ||
| 68 | rm -rf /var/lib/apt/lists/* | ||
| 69 | |||
| 70 | # Create non-root user | ||
| 71 | RUN useradd -m -s /bin/bash user && \ | ||
| 72 | echo "user:user" | chpasswd && \ | ||
| 73 | adduser user sudo && \ | ||
| 74 | echo "user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers | ||
| 75 | |||
| 76 | # Copy Python/Node/Bun/opencode from builder (COPY technique) | ||
| 77 | COPY --from=builder /usr/local/miniconda3 /usr/local/miniconda3 | ||
| 78 | COPY --from=builder /usr/local/node-v22.22.2-linux-x64-glibc-217 /usr/local/node-v22.22.2-linux-x64-glibc-217 | ||
| 79 | COPY --from=builder /usr/local/bun /usr/local/bun | ||
| 80 | |||
| 81 | RUN ln -sf /usr/local/node-v22.22.2-linux-x64-glibc-217/bin/node /usr/local/bin/node && \ | ||
| 82 | ln -sf /usr/local/node-v22.22.2-linux-x64-glibc-217/bin/npm /usr/local/bin/npm && \ | ||
| 83 | ln -sf /usr/local/bun/bin/bun /usr/local/bin/bun | ||
| 84 | |||
| 85 | ENV PATH="/usr/local/miniconda3/bin:/usr/local/node-v22.22.2-linux-x64-glibc-217/bin:/usr/local/bun/bin:${PATH}" | ||
| 86 | |||
| 87 | # Helix: pre-built binary + config from context (COPY technique) | ||
| 88 | COPY helix_config/ /opt/helix_config/ | ||
| 89 | RUN mkdir -p /home/user/.config && \ | ||
| 90 | ln -sf /opt/helix_config /home/user/.config/helix && \ | ||
| 91 | chown -R user:user /home/user/.config | ||
| 92 | ENV PATH="/opt/helix_config/bin:${PATH}" | ||
| 93 | ENV HELIX_RUNTIME=/opt/helix_config | ||
| 94 | |||
| 95 | # Scripts for runtime use | ||
| 96 | COPY scripts/ /home/user/scripts/ | ||
| 97 | RUN chown -R user:user /home/user/scripts && \ | ||
| 98 | chmod +x /home/user/scripts/*.sh | ||
| 99 | |||
| 100 | # code-server | ||
| 101 | RUN curl -fsSL https://code-server.dev/install.sh | sh | ||
| 102 | |||
| 103 | # code-server extensions (run as user so they install to ~/.local) | ||
| 104 | USER user | ||
| 105 | RUN code-server --install-extension golang.go \ | ||
| 106 | && code-server --install-extension cnbcool.cnb-welcome \ | ||
| 107 | && code-server --install-extension formulahendry.code-runner \ | ||
| 108 | && code-server --install-extension ms-kubernetes-tools.vscode-kubernetes-tools \ | ||
| 109 | && code-server --install-extension tencent-cloud.coding-copilot \ | ||
| 110 | && code-server --install-extension github.github-vscode-theme \ | ||
| 111 | && code-server --install-extension ms-ceintl.vscode-language-pack-zh-hans \ | ||
| 112 | && code-server --install-extension eddieposey.vscode-icons-mac \ | ||
| 113 | && code-server --install-extension oderwat.indent-rainbow \ | ||
| 114 | && code-server --install-extension yzhang.markdown-all-in-one | ||
| 115 | |||
| 116 | USER root | ||
| 117 | |||
| 118 | # oh-my-zsh | ||
| 119 | RUN RUNZSH=no CHSH=no sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" && \ | ||
| 120 | chsh -s $(which zsh) user | ||
| 121 | |||
| 122 | # Neovim | ||
| 123 | RUN curl -fsSL https://github.com/neovim/neovim/releases/download/v0.12.2/nvim-linux-x86_64.tar.gz \ | ||
| 124 | -o /tmp/nvim.tar.gz && \ | ||
| 125 | tar xf /tmp/nvim.tar.gz -C /usr/local && \ | ||
| 126 | ln -sf /usr/local/nvim-linux-x86_64/bin/nvim /usr/bin/nvim && \ | ||
| 127 | rm /tmp/nvim.tar.gz | ||
| 128 | |||
| 129 | # tmux config (user's home) | ||
| 130 | RUN cd /home/user && \ | ||
| 131 | git clone --single-branch https://github.com/gpakosz/.tmux.git && \ | ||
| 132 | ln -s -f .tmux/.tmux.conf && \ | ||
| 133 | cp .tmux/.tmux.conf.local . && \ | ||
| 134 | chown -R user:user /home/user | ||
| 135 | |||
| 136 | # Locale (Chinese + English) | ||
| 137 | RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && \ | ||
| 138 | localedef -i zh_CN -c -f UTF-8 -A /usr/share/locale/locale.alias zh_CN.UTF-8 && \ | ||
| 139 | dpkg-reconfigure --frontend=noninteractive locales | ||
| 140 | |||
| 141 | ENV TZ=Asia/Shanghai | ||
| 142 | ENV GIT_TERMINAL_PROMPT=0 | ||
| 143 | ENV LANG=zh_CN.UTF-8 | ||
| 144 | ENV LANGUAGE=zh_CN:zh | ||
| 145 | |||
| 146 | WORKDIR /home/user | ||
| 147 | USER user |
-
Please register or sign in to post a comment