Skip to content

Commit 0fa3142

Browse files
authored
Update Dockerfile
1 parent a765a1c commit 0fa3142

1 file changed

Lines changed: 44 additions & 23 deletions

File tree

Dockerfile

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,92 @@
1+
# ==============================================================================
2+
# Dockerfile for a feature-rich, optimized code-server development environment
13
#
2-
# Dockerfile for a feature-rich code-server with Conda and UV
3-
# Pre-configured for Asia/Shanghai timezone and Alibaba Cloud PyPI mirror.
4-
#
4+
# Features:
5+
# - Base: code-server (latest)
6+
# - Python: Miniforge (Conda) with a pre-created Python 3.11 environment
7+
# - Package Manager: 'uv' (ultra-fast) and 'conda'
8+
# - Optimization (China):
9+
# - Timezone: Asia/Shanghai
10+
# - PyPI Mirror: Alibaba Cloud (for uv/pip)
11+
# - Conda Mirror: TUNA (Tsinghua University)
12+
# - Convenience: Auto-activates conda environment in the terminal
13+
# ==============================================================================
514

615
# Step 1: Start from the official code-server base image.
716
FROM codercom/code-server:latest
817

9-
# Step 2: Set arguments for tool versions.
18+
# Step 2: Set arguments for tool versions for easy updates.
1019
ARG MINIFORGE_VERSION=23.11.0-0
1120
ARG PYTHON_VERSION=3.11
1221

13-
# Step 3: Define environment variables for tool paths and configurations.
22+
# Step 3: Define environment variables for paths and configurations.
1423
ENV CONDA_DIR=/opt/conda
1524
ENV UV_DIR=/home/coder/.local
16-
# Add bin directories to the system PATH.
25+
# Add bin directories of Conda and UV to the system's PATH.
1726
ENV PATH=${CONDA_DIR}/bin:${UV_DIR}/bin:${PATH}
18-
# CRITICAL: Set the timezone environment variable.
27+
# Set the timezone.
1928
ENV TZ=Asia/Shanghai
20-
# CRITICAL: Configure UV to use the Alibaba Cloud mirror by default.
29+
# Configure UV/pip to use the Alibaba Cloud mirror.
2130
ENV UV_INDEX_URL=https://mirrors.aliyun.com/pypi/simple
2231

2332
# Step 4: Switch to the ROOT user for system-level installations.
2433
USER root
2534

26-
# Step 5: Install system dependencies, set timezone, and install Miniforge.
35+
# Step 5: Install system dependencies, set timezone, install and configure Conda.
2736
RUN \
28-
# Update package lists and install necessary tools
37+
# Update package lists and install necessary tools.
2938
apt-get update && apt-get install -y --no-install-recommends \
3039
wget \
3140
curl \
3241
git \
3342
build-essential \
3443
tzdata \
35-
# Set the timezone non-interactively
44+
# Set the timezone non-interactively.
3645
&& ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone \
37-
# Download and install Miniforge
46+
# Download and install Miniforge.
3847
&& wget "https://github.com/conda-forge/miniforge/releases/download/${MINIFORGE_VERSION}/Miniforge3-${MINIFORGE_VERSION}-Linux-x86_64.sh" -O miniforge.sh \
3948
&& /bin/bash miniforge.sh -b -p ${CONDA_DIR} \
4049
&& rm miniforge.sh \
41-
# Give the 'coder' user ownership of the conda directory
50+
# Give the 'coder' user ownership of the conda directory.
4251
&& chown -R coder:coder ${CONDA_DIR} \
43-
# Clean up apt cache to keep the image size down
52+
# Create symbolic links for 'conda' and 'python3' to be accessible by root for debugging.
53+
&& ln -s ${CONDA_DIR}/bin/conda /usr/local/bin/conda \
54+
&& ln -s ${CONDA_DIR}/bin/python /usr/local/bin/python3 \
55+
# Clean up apt cache to reduce image size.
4456
&& apt-get clean \
4557
&& rm -rf /var/lib/apt/lists/*
4658

4759
# Step 6: Switch back to the standard, non-root 'coder' user.
4860
USER coder
4961

50-
# Step 7: As the 'coder' user, install user-specific tools and set up the default environment.
62+
# Step 7: As the 'coder' user, configure tools and create the development environment.
5163
RUN \
52-
# Install 'uv' using its official script
64+
# Install 'uv' (the fast Python package manager).
5365
curl -LsSf https://astral.sh/uv/install.sh | sh && \
5466
\
55-
# Create a default conda environment
67+
# Configure Conda to use Tsinghua University mirrors for faster package downloads.
68+
conda config --set show_channel_urls true && \
69+
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main && \
70+
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r && \
71+
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2 && \
72+
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/conda-forge/ && \
73+
conda config --set-default-channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main && \
74+
\
75+
# Create the default conda environment. This will be fast due to the mirror.
5676
conda create -n py${PYTHON_VERSION} python=${PYTHON_VERSION} -y && \
5777
\
58-
# Pre-install common packages into the new environment using 'uv'.
59-
# This will now automatically use the Alibaba Cloud mirror due to the ENV var.
78+
# Pre-install common Python packages into the new environment using 'uv'.
79+
# This will use the Alibaba Cloud PyPI mirror configured via ENV var.
6080
uv pip install --python=${CONDA_DIR}/envs/py${PYTHON_VERSION}/bin/python \
6181
numpy \
6282
pandas \
6383
matplotlib \
6484
scikit-learn \
65-
jupyterlab && \
85+
jupyterlab \
86+
requests && \
6687
\
67-
# Configure the shell to automatically activate this environment on login
88+
# Configure the shell to automatically activate this environment on login.
6889
echo "conda activate py${PYTHON_VERSION}" >> ~/.bashrc
6990

70-
# Step 8: The base image's entrypoint will start code-server.
71-
# All environment variables (TZ, UV_INDEX_URL, PATH) will be inherited.
91+
# Step 8: The base image's entrypoint will automatically start code-server.
92+
# All our PATH and environment variable configurations will be inherited by the application.

0 commit comments

Comments
 (0)