|
| 1 | +# ============================================================================== |
| 2 | +# Dockerfile for a feature-rich, optimized code-server development environment |
1 | 3 | # |
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 | +# ============================================================================== |
5 | 14 |
|
6 | 15 | # Step 1: Start from the official code-server base image. |
7 | 16 | FROM codercom/code-server:latest |
8 | 17 |
|
9 | | -# Step 2: Set arguments for tool versions. |
| 18 | +# Step 2: Set arguments for tool versions for easy updates. |
10 | 19 | ARG MINIFORGE_VERSION=23.11.0-0 |
11 | 20 | ARG PYTHON_VERSION=3.11 |
12 | 21 |
|
13 | | -# Step 3: Define environment variables for tool paths and configurations. |
| 22 | +# Step 3: Define environment variables for paths and configurations. |
14 | 23 | ENV CONDA_DIR=/opt/conda |
15 | 24 | 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. |
17 | 26 | ENV PATH=${CONDA_DIR}/bin:${UV_DIR}/bin:${PATH} |
18 | | -# CRITICAL: Set the timezone environment variable. |
| 27 | +# Set the timezone. |
19 | 28 | 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. |
21 | 30 | ENV UV_INDEX_URL=https://mirrors.aliyun.com/pypi/simple |
22 | 31 |
|
23 | 32 | # Step 4: Switch to the ROOT user for system-level installations. |
24 | 33 | USER root |
25 | 34 |
|
26 | | -# Step 5: Install system dependencies, set timezone, and install Miniforge. |
| 35 | +# Step 5: Install system dependencies, set timezone, install and configure Conda. |
27 | 36 | RUN \ |
28 | | - # Update package lists and install necessary tools |
| 37 | + # Update package lists and install necessary tools. |
29 | 38 | apt-get update && apt-get install -y --no-install-recommends \ |
30 | 39 | wget \ |
31 | 40 | curl \ |
32 | 41 | git \ |
33 | 42 | build-essential \ |
34 | 43 | tzdata \ |
35 | | - # Set the timezone non-interactively |
| 44 | + # Set the timezone non-interactively. |
36 | 45 | && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone \ |
37 | | - # Download and install Miniforge |
| 46 | + # Download and install Miniforge. |
38 | 47 | && wget "https://github.com/conda-forge/miniforge/releases/download/${MINIFORGE_VERSION}/Miniforge3-${MINIFORGE_VERSION}-Linux-x86_64.sh" -O miniforge.sh \ |
39 | 48 | && /bin/bash miniforge.sh -b -p ${CONDA_DIR} \ |
40 | 49 | && rm miniforge.sh \ |
41 | | - # Give the 'coder' user ownership of the conda directory |
| 50 | + # Give the 'coder' user ownership of the conda directory. |
42 | 51 | && 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. |
44 | 56 | && apt-get clean \ |
45 | 57 | && rm -rf /var/lib/apt/lists/* |
46 | 58 |
|
47 | 59 | # Step 6: Switch back to the standard, non-root 'coder' user. |
48 | 60 | USER coder |
49 | 61 |
|
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. |
51 | 63 | RUN \ |
52 | | - # Install 'uv' using its official script |
| 64 | + # Install 'uv' (the fast Python package manager). |
53 | 65 | curl -LsSf https://astral.sh/uv/install.sh | sh && \ |
54 | 66 | \ |
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. |
56 | 76 | conda create -n py${PYTHON_VERSION} python=${PYTHON_VERSION} -y && \ |
57 | 77 | \ |
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. |
60 | 80 | uv pip install --python=${CONDA_DIR}/envs/py${PYTHON_VERSION}/bin/python \ |
61 | 81 | numpy \ |
62 | 82 | pandas \ |
63 | 83 | matplotlib \ |
64 | 84 | scikit-learn \ |
65 | | - jupyterlab && \ |
| 85 | + jupyterlab \ |
| 86 | + requests && \ |
66 | 87 | \ |
67 | | - # Configure the shell to automatically activate this environment on login |
| 88 | + # Configure the shell to automatically activate this environment on login. |
68 | 89 | echo "conda activate py${PYTHON_VERSION}" >> ~/.bashrc |
69 | 90 |
|
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