Optimize Dockerfile: reduce image size from 4.51GB to 2.16GB
Remove code-server, build-essential, gcc, libc6-dev, pkg-config, libssl-dev from final stage. Add conda clean post-install in builder. Strip unnecessary opencode platform binaries (musl/baseline variants) post-npm-install. Remove redundant COPY layers for opencode (already covered by full node directory copy). Keep opencode.exe entry point (Node.js bootstrap). Constraint: buildkit crashes with 'frontend grpc server closed unexpectedly' on this host; legacy builder used Confidence: high Scope-risk: narrow Directive: opencode.exe is the Node.js bootstrapper, not a Windows binary; do not delete Tested: docker run --rm verified node/npm/bun/python/hx/claude/opencode/nvim all work
Showing
1 changed file
with
9 additions
and
25 deletions
| ... | @@ -17,7 +17,8 @@ RUN apt-get update && \ | ... | @@ -17,7 +17,8 @@ RUN apt-get update && \ |
| 17 | RUN curl -sSLk https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py310_23.11.0-2-Linux-x86_64.sh \ | 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 && \ | 18 | -o /tmp/miniconda.sh && \ |
| 19 | bash /tmp/miniconda.sh -b -p /usr/local/miniconda3 && \ | 19 | bash /tmp/miniconda.sh -b -p /usr/local/miniconda3 && \ |
| 20 | rm /tmp/miniconda.sh | 20 | rm /tmp/miniconda.sh && \ |
| 21 | /usr/local/miniconda3/bin/conda clean -a -y | ||
| 21 | 22 | ||
| 22 | # Node.js (prebuilt binary, no build tools needed) | 23 | # Node.js (prebuilt binary, no build tools needed) |
| 23 | RUN curl -sSLk https://unofficial-builds.nodejs.org/download/release/v22.22.2/node-v22.22.2-linux-x64-glibc-217.tar.gz \ | 24 | RUN curl -sSLk https://unofficial-builds.nodejs.org/download/release/v22.22.2/node-v22.22.2-linux-x64-glibc-217.tar.gz \ |
| ... | @@ -30,8 +31,12 @@ RUN curl -sSLk https://unofficial-builds.nodejs.org/download/release/v22.22.2/no | ... | @@ -30,8 +31,12 @@ RUN curl -sSLk https://unofficial-builds.nodejs.org/download/release/v22.22.2/no |
| 30 | # Bun | 31 | # Bun |
| 31 | RUN curl -fsSL https://bun.sh/install | BUN_INSTALL=/usr/local/bun bash | 32 | RUN curl -fsSL https://bun.sh/install | BUN_INSTALL=/usr/local/bun bash |
| 32 | 33 | ||
| 33 | # opencode-ai | 34 | # opencode-ai + strip unnecessary platform binaries |
| 34 | RUN npm i -g opencode-ai --registry https://mirrors.cloud.tencent.com/npm/ | 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 | ||
| 35 | 40 | ||
| 36 | # ---- Stage 2: Minimal final image ---- | 41 | # ---- Stage 2: Minimal final image ---- |
| 37 | FROM debian:13.4-slim | 42 | FROM debian:13.4-slim |
| ... | @@ -46,8 +51,7 @@ RUN apt-get update && \ | ... | @@ -46,8 +51,7 @@ RUN apt-get update && \ |
| 46 | git git-lfs \ | 51 | git git-lfs \ |
| 47 | zsh tmux \ | 52 | zsh tmux \ |
| 48 | ripgrep jq sudo \ | 53 | ripgrep jq sudo \ |
| 49 | build-essential gcc libc6-dev \ | 54 | vim \ |
| 50 | pkg-config libssl-dev vim \ | ||
| 51 | tzdata locales \ | 55 | tzdata locales \ |
| 52 | lsof nload htop net-tools dnsutils \ | 56 | lsof nload htop net-tools dnsutils \ |
| 53 | openssh-server && \ | 57 | openssh-server && \ |
| ... | @@ -73,8 +77,6 @@ RUN useradd -m -s /bin/bash user && \ | ... | @@ -73,8 +77,6 @@ RUN useradd -m -s /bin/bash user && \ |
| 73 | COPY --from=builder /usr/local/miniconda3 /usr/local/miniconda3 | 77 | COPY --from=builder /usr/local/miniconda3 /usr/local/miniconda3 |
| 74 | COPY --from=builder /usr/local/node-v22.22.2-linux-x64-glibc-217 /usr/local/node-v22.22.2-linux-x64-glibc-217 | 78 | COPY --from=builder /usr/local/node-v22.22.2-linux-x64-glibc-217 /usr/local/node-v22.22.2-linux-x64-glibc-217 |
| 75 | COPY --from=builder /usr/local/bun /usr/local/bun | 79 | COPY --from=builder /usr/local/bun /usr/local/bun |
| 76 | COPY --from=builder /usr/local/node-v22.22.2-linux-x64-glibc-217/lib/node_modules /usr/local/node-v22.22.2-linux-x64-glibc-217/lib/node_modules | ||
| 77 | COPY --from=builder /usr/local/node-v22.22.2-linux-x64-glibc-217/bin/opencode /usr/local/node-v22.22.2-linux-x64-glibc-217/bin/opencode | ||
| 78 | 80 | ||
| 79 | RUN ln -sf /usr/local/node-v22.22.2-linux-x64-glibc-217/bin/node /usr/local/bin/node && \ | 81 | RUN ln -sf /usr/local/node-v22.22.2-linux-x64-glibc-217/bin/node /usr/local/bin/node && \ |
| 80 | ln -sf /usr/local/node-v22.22.2-linux-x64-glibc-217/bin/npm /usr/local/bin/npm && \ | 82 | ln -sf /usr/local/node-v22.22.2-linux-x64-glibc-217/bin/npm /usr/local/bin/npm && \ |
| ... | @@ -95,24 +97,6 @@ COPY scripts/ /home/user/scripts/ | ... | @@ -95,24 +97,6 @@ COPY scripts/ /home/user/scripts/ |
| 95 | RUN chown -R user:user /home/user/scripts && \ | 97 | RUN chown -R user:user /home/user/scripts && \ |
| 96 | chmod +x /home/user/scripts/*.sh | 98 | chmod +x /home/user/scripts/*.sh |
| 97 | 99 | ||
| 98 | # code-server | ||
| 99 | RUN curl -fsSL https://code-server.dev/install.sh | sh | ||
| 100 | |||
| 101 | # code-server extensions (run as user so they install to ~/.local) | ||
| 102 | USER user | ||
| 103 | RUN code-server --install-extension golang.go \ | ||
| 104 | && code-server --install-extension cnbcool.cnb-welcome \ | ||
| 105 | && code-server --install-extension formulahendry.code-runner \ | ||
| 106 | && code-server --install-extension ms-kubernetes-tools.vscode-kubernetes-tools \ | ||
| 107 | && code-server --install-extension tencent-cloud.coding-copilot \ | ||
| 108 | && code-server --install-extension github.github-vscode-theme \ | ||
| 109 | && code-server --install-extension ms-ceintl.vscode-language-pack-zh-hans \ | ||
| 110 | && code-server --install-extension eddieposey.vscode-icons-mac \ | ||
| 111 | && code-server --install-extension oderwat.indent-rainbow \ | ||
| 112 | && code-server --install-extension yzhang.markdown-all-in-one | ||
| 113 | |||
| 114 | USER root | ||
| 115 | |||
| 116 | # oh-my-zsh | 100 | # oh-my-zsh |
| 117 | RUN RUNZSH=no CHSH=no sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" && \ | 101 | RUN RUNZSH=no CHSH=no sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" && \ |
| 118 | chsh -s $(which zsh) user | 102 | chsh -s $(which zsh) user | ... | ... |
-
Please register or sign in to post a comment