code-server / Dockerfile
cacode's picture
Update Dockerfile
e520895 verified
raw
history blame
3.11 kB
FROM debian:bookworm-slim
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Etc/UTC
ENV PORT=7860
ENV HOME=/home/coder
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# -----------------------------
# 1) 基础系统 + 重度开发工具链
# -----------------------------
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates curl wget git bash sudo tini gnupg dirmngr jq \
unzip zip xz-utils less vim nano openssh-client \
# C/C++
build-essential gcc g++ make cmake ninja-build gdb lldb clang clangd pkg-config \
# Python
python3 python3-pip python3-venv python3-dev \
# Java + build tools
openjdk-17-jdk maven gradle \
# Node.js
nodejs npm \
# 其他常用工具
ripgrep fd-find procps \
# rust/go(重度开发常见)
rustc cargo golang-go \
&& rm -rf /var/lib/apt/lists/*
# -----------------------------
# 2) 安装 code-server
# -----------------------------
RUN curl -fsSL https://code-server.dev/install.sh | sh
# -----------------------------
# 3) Node 包管理器补充
# -----------------------------
RUN npm install -g yarn pnpm
# -----------------------------
# 4) 修复 PEP668:用 venv 安装 Python 包
# -----------------------------
RUN python3 -m venv /opt/venv
ENV PATH="/opt/venv/bin:${PATH}"
RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \
pip install --no-cache-dir \
numpy pandas scipy scikit-learn matplotlib seaborn plotly \
jupyter jupyterlab ipykernel notebook \
requests httpx aiohttp pyyaml python-dotenv tqdm rich \
flask fastapi uvicorn[standard] pydantic \
sqlalchemy alembic psycopg2-binary redis \
pytest pytest-cov black isort mypy ruff pre-commit
# -----------------------------
# 5) 安装 Codex CLI(可选,失败不阻断)
# -----------------------------
RUN npm install -g @openai/codex || true
# -----------------------------
# 6) 创建运行用户
# -----------------------------
RUN useradd -m -u 1000 -s /bin/bash coder && \
echo "coder ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers && \
mkdir -p /home/coder/.config/code-server /home/coder/.codex && \
chown -R coder:coder /home/coder
# 可选:给 coder 预装常用 VS Code 扩展(失败不阻断)
RUN su - coder -c "code-server --install-extension ms-python.python || true" && \
su - coder -c "code-server --install-extension ms-toolsai.jupyter || true" && \
su - coder -c "code-server --install-extension ms-vscode.cpptools || true" && \
su - coder -c "code-server --install-extension llvm-vs-code-extensions.vscode-clangd || true" && \
su - coder -c "code-server --install-extension vscjava.vscode-java-pack || true" && \
su - coder -c "code-server --install-extension redhat.vscode-yaml || true" && \
su - coder -c "code-server --install-extension esbenp.prettier-vscode || true"
COPY --chown=coder:coder start.sh /usr/local/bin/start.sh
RUN chmod +x /usr/local/bin/start.sh
USER coder
WORKDIR /home/coder
EXPOSE 7860
ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["/usr/local/bin/start.sh"]