v1.1.0: Alpine 轻量级 Docker 开发环境 + 敏感凭证清理

This commit is contained in:
lxy
2026-07-27 13:59:18 +08:00
parent feb76081a0
commit ccca0fa62b
51 changed files with 6125 additions and 993 deletions
+41 -90
View File
@@ -1,107 +1,58 @@
# WorkPod - 全栈开发环境容器 (本地包构建版)
# 包含:Ubuntu + Python + Go + Rust + Node + MySQL + Redis + Claude Code 2.1.79 + OpenClaw
# WorkPod Alpine - 轻量级开发环境(多阶段构建)
FROM ubuntu:22.04
# ============ 阶段1: 构建阶段 ============
FROM alpine:3.23 AS builder
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Shanghai
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
apk update && apk add --no-cache xz libstdc++
# ============ 配置阿里云镜像源 ============
RUN sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list && \
sed -i 's/security.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
# ============ 基础工具 (合并安装减少层数) ============
RUN apt-get update && apt-get install -y --no-install-recommends \
# 基础工具
curl wget git vim nano less tree jq \
# 系统工具
procps htop net-tools iputils-ping lsof \
# 压缩工具
zip unzip xz-utils \
# 构建工具
build-essential pkg-config \
# SSL/加密
ca-certificates gnupg \
# SSH + PTY 支持
openssh-server locales \
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/* \
&& mkdir -p /var/run/sshd \
&& echo 'root:workpod123' | chpasswd \
&& sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
# 中文和 UTF-8 支持
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
ENV LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8
# ============ Python ============
RUN apt-get update && apt-get install -y --no-install-recommends \
python3 python3-pip python3-venv \
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/* \
&& ln -sf /usr/bin/python3 /usr/bin/python
# ============ 复制本地包到镜像 ============
COPY packages/ /tmp/packages/
# ============ Node.js v24.14.0 (Krypton LTS) ============
RUN cd /tmp/packages \
&& tar -xf node-v24.14.0-linux-x64.tar.xz -C /usr/local --strip-components=1 \
&& npm install -g npm@latest pnpm yarn \
&& npm cache clean --force
# ============ Go 1.26.1 (最新版) ============
ENV GOPATH=/root/go
ENV PATH=/usr/local/go/bin:$GOPATH/bin:$PATH
RUN cd /tmp/packages \
&& tar -xzf go1.26.1.linux-amd64.tar.gz -C /usr/local
# ============ Rust 1.94.0 ============
ENV CARGO_HOME=/root/.cargo RUSTUP_HOME=/root/.rustup
ENV PATH=$CARGO_HOME/bin:$PATH
RUN mkdir -p /opt/rust $CARGO_HOME/bin \
# 安装 Node.js + npm 全局包
RUN mkdir -p /opt/node \
&& cd /tmp/packages \
&& tar -xf rust-1.94.0-x86_64-unknown-linux-gnu.tar.xz -C /opt/rust \
&& ln -sf /opt/rust/rust-1.94.0-x86_64-unknown-linux-gnu/bin/* $CARGO_HOME/bin/
# ============ Claude Code + OpenClaw (离线安装) ============
RUN cd /tmp/packages \
&& npm install -g claude-code-2.1.79.tgz \
&& npm install -g openclaw-2026.3.13.tgz \
&& tar -xzf node-v24.14.1-linux-x64-musl.tar.gz -C /opt/node --strip-components=1 \
&& export PATH="/opt/node/bin:$PATH" \
&& npm install -g npm@10 \
&& npm config set registry https://registry.npmmirror.com \
&& npm install -g "@anthropic-ai/claude-code@latest" \
&& npm install -g "@z_ai/coding-helper@latest" \
&& npm cache clean --force
# ============ MySQL 8.0 (手动启动) ============
RUN apt-get update && apt-get install -y --no-install-recommends \
mysql-server \
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/* \
&& mkdir -p /var/run/mysqld \
&& chown mysql:mysql /var/run/mysqld
# ============ 阶段2: 运行阶段 ============
FROM alpine:3.23
# ============ Redis (手动启动) ============
RUN apt-get update && apt-get install -y --no-install-recommends \
redis-server \
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*
ENV TZ=Asia/Shanghai LANG=C.UTF-8
# ============ 更多常用工具 ============
RUN apt-get update && apt-get install -y --no-install-recommends \
# 网络工具
netcat-openbsd \
# 文本处理
ripgrep fd-find \
# 进程管理
tmux \
# 其他
bash-completion \
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*
# 基础工具 + SSH + ttyd
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
apk update && apk add --no-cache \
curl git ca-certificates openssh-server openrc \
bash ttyd tmux libstdc++ \
&& mkdir -p /run/openrc && touch /run/openrc/softlevel \
&& ssh-keygen -A \
&& echo "root:${ROOT_PASSWORD:-workpod123}" | chpasswd \
&& sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
# ============ 清理临时包 ============
RUN rm -rf /tmp/packages
# 从构建阶段复制 Node.js 和全局包(仅产物,无缓存)
COPY --from=builder /opt/node /usr/local
# 固化 npm 镜像源(运行时也需要,builder 的 npmrc 未被 COPY 包含)
RUN npm config set registry https://registry.npmmirror.com
# ============ 工作目录 ============
WORKDIR /workspace
# ============ 启动脚本 ============
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
COPY --chmod=755 entrypoint.sh /entrypoint.sh
COPY --chmod=755 ttyd-session.sh /opt/ttyd-session.sh
EXPOSE 22 80 443 3306 6379
LABEL maintainer="workpod" \
org.opencontainers.image.title="WorkPod Alpine" \
org.opencontainers.image.description="Lightweight development environment (Alpine)" \
org.opencontainers.image.version="1.1.0"
EXPOSE 22 7681
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD netstat -tlnp 2>/dev/null | grep -qE ':(22|7681)\b' || exit 1
ENTRYPOINT ["/entrypoint.sh"]